PivotOJ

A Rank Problem

시간 제한: 1000ms메모리 제한: 1024MB출처: ICPC ECNA 2020-2021BOJ 21156

문제

Coach is fed up with sports rankings -- he thinks those who make up these bogus orderings are just nuts.  In Coach's opinion changes in rankings should be evidence-based only.  For example, suppose the 44th place team plays the 11st place team and loses.  Why should the rankings be altered? The "worse" team lost to the "better" team, so nothing should change in the rankings.  Put another way, there's no evidence that the ordering should change so why change it?  The only time you change something is if, say, the 44th place team beats the 11st place team.  NOW you have evidence that the rankings should change!  Specifically, the 11st place team should be put directly below the 44th place team (we now have evidence that backs this up) and the teams in 22nd through 44th place should each move up one.  The result is that the former 11st place team is now in 44th, one position below the team that beat it, the former 44th place team now in 33rd.  Note that the relative positions of the teams now in 11st to 33rd place do not change -- there was no evidence that they should.

To generalize this process, assume the team in position nn beats the team in position mm.  If n<mn < m then there should be no change in the rankings; if n>mn > m then all teams in positions m+1,m+2,,nm+1, m+2, \ldots, n should move up one position and the former team in position mm should be moved to position nn.

For example, assume there are 55 teams initially ranked in the order T11 (best), T22, T33, T44, T55 (worst).  Suppose T44 beats T11.  Then as described above the new rankings should become T22, T33, T44, T11, T55.  Now in the next game played let's say T33 beats T11. After this the rankings should not change -- the better ranked team beat the worse ranked team.  If in the next game T55 beats T33 the new rankings would be T22, T44, T11, T55, T33, and so on.

Coach was all set to write a program to implement this scheme but then he heard about ties in the English Premier League.  The last we saw him he was standing motionless, staring out of his window.  We guess it's up to you to write the program.

입력

Input begins with a line containing two positive integers nn mm (n,m100n, m \leq 100) indicating the number of teams and the number of games played.  Team names are \mboxT1,\mboxT2,,\mboxTnT1, T2, \ldots, Tn and initially each team \mboxTiTi is in position ii in the rankings (i.e., team \mboxT1T1 is in 11st place and team \mboxTnTn is in last place).  Following the first line are mm lines detailing a set of games in chronological order.  Each of these lines has the form \mboxTiTi \mboxTjTj (1i,jn,ij1 \leq i,j \leq n, i \neq j) indicating that team \mboxTiTi beat team \mboxTjTj.

출력

Output a single line listing the final ranking of the teams. Separate team names with single spaces.

예제

예제 1

입력
5 3
T4 T1
T3 T1
T5 T3
출력
T2 T4 T1 T5 T3

예제 2

입력
8 4
T4 T1
T1 T2
T2 T3
T3 T4
출력
T1 T2 T3 T4 T5 T6 T7 T8
코드를 제출하려면 로그인하세요.