Logo
(追記) (追記ここまで)

33597번 - Condorcet Elections 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 2048 MB26201976.000%

문제

It is a municipality election year. Even though the leader of the country has not changed for two decades, the elections are always transparent and fair.

There are $n$ political candidates, numbered from 1ドル$ to $n,ドル contesting the right to govern. The elections happen using a variation of the Ranked Voting System. In their ballot, each voter will rank all $n$ candidates from most preferable to least preferable. That is, each vote is a permutation of $\{1, 2, \dots , n\},ドル where the first element of the permutation corresponds to the most preferable candidate.

We say that candidate $a$ defeats candidate $b$ if in more than half of the votes candidate $a$ is more preferable than candidate $b$.

As the election is fair and transparent, the state television has already decreed a list of $m$ facts—the $i$-th fact being “candidate $a_i$ has defeated candidate $b_i$”—all before the actual election!

You are in charge of the election commission and tallying up the votes. You need to present a list of votes that produces the outcome advertised on television, or to determine that it is not possible. However, you are strongly encouraged to find a solution, or you might upset higher-ups.

입력

The first line contains integers $n$ and $m$ (2ドル ≤ n ≤ 50,ドル 1ドル ≤ m ≤ \frac{n(n-1)}{2}$) — the number of parties and the number of pairs with known election outcomes.

The $i$-th of the following $m$ lines contains two integers $a_i$ and $b_i$ (1ドル ≤ a_i , b_i ≤ n,ドル $a_i \ne b_i$) — candidate $a_i$ defeats candidate $b_i$.

Each unordered pair $\{a_i , b_i\}$ is given at most once.

출력

Print YES if there is a list of votes matching the facts advertised on television. Otherwise, print NO.

If there is a valid list of votes, print one such list in the following lines.

Print the number $k$ of votes cast (1ドル ≤ k ≤ 50,円 000$). It can be shown that if there is a valid list of votes, there is one with at most 50ドル,円 000$ votes.

Then print $k$ lines. The $i$-th of these lines consists of a permutation of $\{1, 2, \dots , n\}$ describing the $i$-th vote. The first number in the permutation is the most preferable candidate and the last one is the least preferable candidate.

For 1ドル ≤ i ≤ m,ドル $a_i$ shall appear earlier than $b_i$ in more than $k/2$ of the $k$ permutations. For pairs of candidates $\{a, b\}$ not appearing in the election requirements list, the outcome can be arbitrary, including neither of $a$ and $b$ defeating the other.

제한

예제 입력 1

2 1
1 2

예제 출력 1

YES
1
1 2

예제 입력 2

3 3
1 2
2 3
3 1

예제 출력 2

YES
3
1 2 3
2 3 1
3 1 2

Observe that candidate 1ドル$ defeats candidate 2ドル$ because it goes earlier in two out of three voters’ permutations, which is more than half of all votes. Similarly, candidate 2ドル$ defeats candidate 3ドル,ドル and candidate 3ドル$ defeats candidate 1ドル$.

힌트

출처

ICPC > Regionals > Europe > European Championship > The 2025 ICPC European Championship A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /