Condorcet Elections
시간 제한2초메모리 제한2048 MB
n명의 후보 사이에 주어진 승패 관계를 만족하도록, 최대 50000개의 순위 투표를 구성하거나 불가능함을 판정한다.
문제
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 political candidates, numbered from to , contesting the right to govern. The elections happen using a variation of the Ranked Voting System. In their ballot, each voter will rank all candidates from most preferable to least preferable. That is, each vote is a permutation of , where the first element of the permutation corresponds to the most preferable candidate.
We say that candidate defeats candidate if in more than half of the votes candidate is more preferable than candidate .
As the election is fair and transparent, the state television has already decreed a list of facts—the -th fact being “candidate has defeated candidate ”—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 and (, ) — the number of parties and the number of pairs with known election outcomes.
The -th of the following lines contains two integers and (, ) — candidate defeats candidate .
Each unordered pair 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 of votes cast (). It can be shown that if there is a valid list of votes, there is one with at most votes.
Then print lines. The -th of these lines consists of a permutation of describing the -th vote. The first number in the permutation is the most preferable candidate and the last one is the least preferable candidate.
For , shall appear earlier than in more than of the permutations. For pairs of candidates not appearing in the election requirements list, the outcome can be arbitrary, including neither of and defeating the other.