QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100

#3618. 一个排名问题

Statistiques

教练对体育排名感到厌倦——他认为那些制定这些虚假排名的人简直是疯了。在教练看来,排名的变动应该仅基于证据。例如,假设第 4 名的队伍与第 1 名的队伍比赛并输了。为什么要改变排名呢?“较差”的队伍输给了“较好”的队伍,因此排名不应有任何改变。换句话说,没有证据表明排名应该改变,所以为什么要改变它呢?只有当,比如说,第 4 名的队伍击败了第 1 名的队伍时,你才需要改变排名。现在你有证据表明排名应该改变了!具体来说,原第 1 名的队伍应该被直接放在原第 4 名的队伍之后(我们现在有了支持这一点的证据),而原第 2 名到第 4 名的队伍应各自向前移动一位。结果是,原第 1 名的队伍现在排在第 4 位,即击败它的队伍之后的一位,而原第 4 名的队伍现在排在第 3 位。注意,原先排在第 1 到第 3 位的队伍之间的相对位置没有改变——因为没有证据表明它们应该改变。

为了推广这个过程,假设排在第 $n$ 位的队伍击败了排在第 $m$ 位的队伍。如果 $n < m$,则排名不应有任何变化;如果 $n > m$,则所有排在第 $m+1, m+2, \dots, n$ 位的队伍都应向前移动一个位置,而原先排在第 $m$ 位的队伍应被移动到第 $n$ 位。

例如,假设有 5 支队伍,初始排名顺序为 T1(最好)、T2、T3、T4、T5(最差)。假设 T4 击败了 T1。那么根据上述规则,新的排名应变为 T2、T3、T4、T1、T5。现在在下一场比赛中,假设 T3 击败了 T1。在此之后,排名不应改变——因为排名较好的队伍击败了排名较差的队伍。如果接下来的比赛中 T5 击败了 T3,那么新的排名将变为 T2、T4、T1、T5、T3,依此类推。

教练原本准备编写一个程序来实现这个方案,但他听说了英超联赛中的平局情况。我们最后一次见到他时,他正一动不动地站在窗前凝视。我们猜想,编写这个程序的任务就交给你了。

输入格式

输入的第一行包含两个正整数 $n$ 和 $m$ ($n, m \le 100$),分别表示队伍的数量和进行的比赛场数。队伍名称为 T1, T2, $\dots, Tn$,初始时每支队伍 Ti 排在第 $i$ 位(即 T1 排在第 1 位,Tn 排在最后一位)。接下来的 $m$ 行按时间顺序详细说明了一系列比赛。每一行格式为 Ti Tj ($1 \le i, j \le n, i \neq j$),表示队伍 Ti 击败了队伍 Tj。

输出格式

输出一行,列出队伍的最终排名。队伍名称之间用单个空格分隔。

样例

样例输入 1

5 3
T4 T1
T3 T1
T5 T3

样例输出 1

T2 T4 T1 T5 T3

样例输入 2

8 4
T4 T1
T1 T2
T2 T3
T3 T4

样例输出 2

T1 T2 T3 T4 T5 T6 T7 T8

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.