QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#3988. 邪恶的选举

الإحصائيات

Dylan 是一位腐败的政客,他正试图窃取一场选举。他已经使用了一种精神控制技术来奴役一组政府代表 $U$。然而,负责选出选举获胜者的代表是另一组人 $V$。Dylan 希望他不需要再次使用精神控制装置,因此他想知道 $V$ 中的哪些代表可以被 $U$ 中的代表说服,从而投票给他。

幸运的是,代表们往往很有说服力。你有一份代表对 $(A, B)$ 的列表,表示 $A$ 可以说服 $B$ 投票给 Dylan。这种说服可以形成链条;例如,如果 Dylan 精神控制了 $A$,$A$ 可以说服 $B$,$B$ 可以说服 $C$,那么 $A$ 实际上也可以说服 $C$。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10$),表示测试用例的数量。每个测试用例的第一行包含三个空格分隔的整数 $u, v, m$ ($1 \le u, v, m \le 10,000$)。第二行包含 $u$ 个空格分隔的代表名字,这些代表属于集合 $U$。第三行包含 $v$ 个空格分隔的代表名字,这些代表属于集合 $V$。接下来的 $m$ 行,每行包含一对形式为 $A\ B$ 的名字,其中 $A$ 和 $B$ 是两个代表的名字,表示 $A$ 可以说服 $B$ 投票给 Dylan。名字是长度在 1 到 10 之间且仅由小写字母(a 到 z)组成的字符串。

输出格式

对于每个测试用例,按字母顺序输出一个空格分隔的列表,列出所有可以被 $U$ 中的代表通过链条说服而投票给 Dylan 的 $V$ 中的代表名字。

样例

输入格式 1

2
1 1 1
alice
bob
alice bob
5 5 5
adam bob joe jill peter
rob peter nicole eve saul
harry ron
eve adam
joe chris
jill jack
jack saul

输出格式 1

bob
peter saul

说明

在第二个测试用例中,Jill 可以通过 Jack 说服 Saul,而 Peter 已经被精神控制了。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.