Election of Evil(搜索)

题目描述

Dylan is a corrupt politician trying to steal an election. He has already used a mind-control technique to enslave some set U of government representatives. However, the representatives who will be choosing the winner of the election is a different set V . Dylan is hoping that he does not need to use his mind-control device again, so he is wondering which representatives from V can be convinced to vote for him by representatives from U.
Luckily, representatives can be persuasive people. You have a list of pairs (A, B) of represenatives, which indicate that A can convice B to vote for Dylan. These can work in chains; for instance, if Dylan has mind-controlled A, A can convince B, and B can convince C, then A can effectively convince C as well.

 

输入

The first line contains a single integer T (1 ≤ T ≤ 10), the number of test cases. The first line of each test case contains three space-separated integers, u, v, and m (1 ≤ u, v, m ≤ 10,000). The second line contains a space-separated list of the u names of representatives in U. The third line contains a space-separated list of the v names of representatives from V . Each of the next m lines contains a pair of the form A B, where A and B are names of two representatives such that A can convince B to vote for Dylan. Names are strings of length between 1 and 10 that only consists of lowercase letters (a to z).

 

输出

For each test case, output a space-separated list of the names of representatives from T who can be convinced to vote for Dylan via a chain from S, in alphabetical order.

#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
mapmp;
string str1[1008611],str2[1008611];
string ch1,ch2,ans[1008611];
vectorve[1008611];
ll vis[1008611];
void dfs(ll x){for(ll i=0;i>str1[i];if(!mp[str1[i]]){mp[str1[i]]=loc++;}}for(int i=0;i>str2[i];if(!mp[str2[i]]){mp[str2[i]]=loc++;}}for(int i=0;i>ch1>>ch2;if(!mp[ch1]){mp[ch1]=loc++;}if(!mp[ch2]){mp[ch2]=loc++;}ve[mp[ch1]].push_back(mp[ch2]);}for(int i=0;i

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部