Condorcet Elections

시간 제한2초메모리 제한2048 MB

요약
n명의 후보 사이에 주어진 승패 관계를 만족하도록, 최대 50000개의 순위 투표를 구성하거나 불가능함을 판정한다.
난이도

어려움10점 중 8점

유형
그리디, 그래프, 위상 정렬, 구현
정답자
아직 제출이 없습니다

문제

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 nn political candidates, numbered from 11 to nn, contesting the right to govern. The elections happen using a variation of the Ranked Voting System. In their ballot, each voter will rank all nn candidates from most preferable to least preferable. That is, each vote is a permutation of 1,2,…,n\\{1, 2, \dots , n\\}, where the first element of the permutation corresponds to the most preferable candidate.

We say that candidate aa defeats candidate bb if in more than half of the votes candidate aa is more preferable than candidate bb.

As the election is fair and transparent, the state television has already decreed a list of mm facts—the ii-th fact being “candidate a_ia\_i has defeated candidate b_ib\_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 nn and mm (2≤n≤502 ≤ n ≤ 50, 1≤m≤n(n−1)21 ≤ m ≤ \frac{n(n-1)}{2}) — the number of parties and the number of pairs with known election outcomes.

The ii-th of the following mm lines contains two integers a_ia\_i and b_ib\_i (1≤a_i,b_i≤n1 ≤ a\_i , b\_i ≤ n, a_i≠b_ia\_i \ne b\_i) — candidate a_ia\_i defeats candidate b_ib\_i.

Each unordered pair a_i,b_i\\{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 kk of votes cast (1≤k≤50,0001 ≤ k ≤ 50\\, 000). It can be shown that if there is a valid list of votes, there is one with at most 50,00050\\, 000 votes.

Then print kk lines. The ii-th of these lines consists of a permutation of 1,2,…,n\\{1, 2, \dots , n\\} describing the ii-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≤m1 ≤ i ≤ m, a_ia\_i shall appear earlier than b_ib\_i in more than k/2k/2 of the kk permutations. For pairs of candidates a,b\\{a, b\\} not appearing in the election requirements list, the outcome can be arbitrary, including neither of aa and bb defeating the other.

예제2

  1. 예제 1

    입력
    2 1
    1 2
    
    예상 출력
    YES
    1
    1 2
    
  2. 예제 2

    입력
    3 3
    1 2
    2 3
    3 1
    
    예상 출력
    YES
    3
    1 2 3
    2 3 1
    3 1 2