G - Round Robin Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600600

問題文

11 から NN までの番号がついた NN 人が総当たり戦をしています。
すなわち、全ての組 (i,j)(1i<jN)(i,j) (1\leq i \lt j \leq N) について、人 ii と人 jj11 回試合をするので、試合は合計で N(N1)2\frac{N(N-1)}{2} 試合行われます。
なお、試合は必ず一方が勝者、もう一方が敗者となり、引き分けとなることはありません。

既に MM 試合が終了しており、ii 試合目では人 WiW_i が人 LiL_i に勝ちました。

総当たり戦が終了したとき、単独優勝をする可能性のある人を列挙してください。
ただし単独優勝とは、その人の勝利数が、他のどの人の勝利数よりも多いことを言います。

制約

  • 2N502\leq N \leq 50
  • 0MN(N1)20\leq M \leq \frac{N(N-1)}{2}
  • 1Wi,LiN1\leq W_i,L_i\leq N
  • WiLiW_i \neq L_i
  • iji\neq j ならば、(Wi,Li)(Wj,Lj)(W_i,L_i) \neq (W_j,L_j)
  • (Wi,Li)(Lj,Wj)(W_i,L_i) \neq (L_j,W_j)
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

NN MM
W1W_1 L1L_1
W2W_2 L2L_2
\vdots
WMW_M LML_M

出力

単独優勝をする可能性のある人の番号の集合を A=(A1,A2,,AK)(A1<A2<<AK)A=(A_1,A_2,\dots,A_K) (A_1\lt A_2 \lt \dots \lt A_K) として、AA を昇順に空白区切りで出力せよ。
すなわち、以下の形式で出力せよ。

A1A_1 A2A_2 \dots AKA_K

入力例 1Copy

Copy
4 2
2 1
2 3

出力例 1Copy

Copy
2 4

2,42,4 は単独優勝する可能性があり、人 1,31,3 は単独優勝する可能性がありません。
なお、4 2 などの出力は不正解となることに注意してください。


入力例 2Copy

Copy
3 3
1 2
2 3
3 1

出力例 2Copy

Copy

単独優勝する可能性のある人がいないこともあります。


入力例 3Copy

Copy
7 9
6 5
1 2
3 4
5 3
6 2
1 5
3 2
6 4
1 4

出力例 3Copy

Copy
1 3 6 7

Score : 600600 points

Problem Statement

NN players numbered 11 through NN will participate in a round-robin tournament.
Specifically, for every pair (i,j)(1i<jN)(i,j) (1\leq i \lt j \leq N), Player ii and Player jj play a match against each other once, for a total of N(N1)2\frac{N(N-1)}{2} matches.
In every match, one of the players will be a winner and the other will be a loser; there is no draw.

MM matches have already ended. In the ii-th match, Player WiW_i won Player LiL_i.

List all the players who may become the unique winner after the round-robin tournament is completed.
A player is said to be the unique winner if the number of the player's wins is strictly greater than that of any other player.

Constraints

  • 2N502\leq N \leq 50
  • 0MN(N1)20\leq M \leq \frac{N(N-1)}{2}
  • 1Wi,LiN1\leq W_i,L_i\leq N
  • WiLiW_i \neq L_i
  • If iji\neq j, then (Wi,Li)(Wj,Lj)(W_i,L_i) \neq (W_j,L_j).
  • (Wi,Li)(Lj,Wj)(W_i,L_i) \neq (L_j,W_j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM
W1W_1 L1L_1
W2W_2 L2L_2
\vdots
WMW_M LML_M

Output

Let A=(A1,A2,,AK)(A1<A2<<AK)A=(A_1,A_2,\dots,A_K) (A_1\lt A_2 \lt \dots \lt A_K) be the set of indices of players that may become the unique winner. Print AA in the increasing order, with spaces in between.
In other words, print in the following format.

A1A_1 A2A_2 \dots AKA_K

Sample Input 1Copy

Copy
4 2
2 1
2 3

Sample Output 1Copy

Copy
2 4

Players 22 and 44 may become the unique winner, while Players 11 and 33 cannot.
Note that output like 4 2 is considered to be incorrect.


Sample Input 2Copy

Copy
3 3
1 2
2 3
3 1

Sample Output 2Copy

Copy

It is possible that no player can become the unique winner.


Sample Input 3Copy

Copy
7 9
6 5
1 2
3 4
5 3
6 2
1 5
3 2
6 4
1 4

Sample Output 3Copy

Copy
1 3 6 7


2025-03-31 (Mon)
21:55:01 +00:00