#P1960. Unique Football Team Ranking

    ID: 15242 Type: Default 1000ms 256MiB

Unique Football Team Ranking

Unique Football Team Ranking

You are a sports journalist working for a sports newspaper. You have been given a challenging task: there are (N) football teams participating in a competition. You are provided with some match results, and you need to determine the ranking of every team from (1) to (N).

The following information is known:
1. There are no draws.
2. No two teams share the same rank.
3. For every pair ( (a, b) ) satisfying (1 \le a < b \le N), the team ranked (a) always beats the team ranked (b).

Given some partial match results, your task is to output a ranking order that is consistent with the match results and to decide whether there exists another valid ranking order (i.e. an alternative ranking) which also satisfies the provided results.

inputFormat

The input begins with a line containing two integers (N) and (M), where (N) is the number of teams and (M) is the number of match results. Each of the next (M) lines contains two integers (u) and (v), which indicates that team (u) beat team (v).

outputFormat

Output two lines. The first line contains (N) integers representing a valid ranking order of the teams from rank (1) (the best) to rank (N) (the worst). The second line should be either YES if there exists an alternative ranking order (different from the one you output) satisfying the match results, or NO if the ranking order is unique.

sample

4 6
1 2
1 3
1 4
2 3
2 4
3 4
1 2 3 4

NO

</p>