QOJ.ac

QOJ

时间限制: 1 s 内存限制: 2048 MB 总分: 100

#2653. 交换位置

统计

动物们在进入一个无狩猎区(在那里它们将过上更轻松的生活)之前,会在隔离区的队伍中排队等待。

当进入隔离区时,动物必须向守卫登记。守卫记下动物的物种,然后该动物被允许加入队伍的末尾,排在最后一位。在队伍的另一端,动物必须办理离队手续:当排在队伍第一位的动物最终被允许进入无狩猎区时,另一名守卫会记下该动物的物种。因此,每名守卫都维护着一份动物物种列表,按动物登记进入或离开的先后顺序记录。总共有 $N$ 只动物(代表 $S$ 个物种)完成了登记(并因此完成了离队)。

然而,动物进入等待队列和离开队列的顺序可能会有所不同。事实上,有些动物物种之间是朋友关系,因此如果两个属于此类物种的动物在队伍中相邻,它们可以商定交换位置。

你拥有一份在队伍中相邻时可以交换位置的动物物种对列表:这份列表包含 $L$ 对。你拿到了第一名守卫维护的登记列表。根据动物们决定交换位置的情况,可能会有多种不同的离队列表。在所有可能的列表中,哪一个在字典序中最小?

输入格式

输入包含以下行: 第 1 行包含三个空格分隔的整数 $S$、$L$ 和 $N$。$S$ 是动物物种的数量,$L$ 是互为朋友的物种对的数量,$N$ 是进入等待队列的动物总数。 第 $i+2$ 行(对于 $0 \le i < S$)包含一个代表物种的名称:该名称由单个单词组成,包含“A”到“Z”之间的大写字母,长度在 1 到 20 个字符之间。 第 $i+S+2$ 行(对于 $0 \le i < L$)包含两个空格分隔的物种名称 $A$ 和 $B$,表示 $A$ 和 $B$ 是朋友。 第 $S+L+2$ 行表示登记列表,包含 $N$ 个空格分隔的物种名称:对于所有 $1 \le k \le N$,第 $k$ 个单词是第 $k$ 个进入队列的动物的物种名称。

数据范围

  • $1 \le S \le 200$
  • $0 \le L \le 10\,000$
  • $1 \le N \le 100\,000$

输出格式

输出应包含一行,包含 $N$ 个单词 $w_0, \dots, w_{N-1}$,以空格分隔:该列表 $w_0, \dots, w_{N-1}$ 必须是所有可能的离队列表中,字典序最小的那一个。

样例

样例输入 1

3 2 6
ANTILOPE
CAT
ANT
CAT ANTILOPE
ANTILOPE ANT
ANT CAT CAT ANTILOPE CAT ANT

样例输出 1

ANT ANTILOPE CAT CAT CAT ANT

说明 1

六种可能的离队顺序,按(递增)字典序排序如下:

  1. ANT ANTILOPE CAT CAT CAT ANT
  2. ANT CAT ANTILOPE CAT CAT ANT
  3. ANT CAT CAT ANTILOPE CAT ANT
  4. ANT CAT CAT CAT ANT ANTILOPE
  5. ANT CAT CAT CAT ANTILOPE ANT
  6. ANTILOPE ANT CAT CAT CAT ANT

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.