Under construction

Still being built. Things may change

Viking Village

Time limit2sMemory limit1024 MB

Summary
Given a directed graph, decide whether a rooted tree has the same reachable set for every node, and print its parent array if one exists.
Level

Medium7 of 10

Topics
Graph, Topological sort, DFS
Solved
No attempts yet

Problem

Hiccup noticed that the chain of command in his village is very tangled. The village has nn Vikings, numbered from 11 to nn. Hiccup wrote down mm pairs aia_i, bib_i, meaning that the aia_i-th Viking can pass a task to the bib_i-th Viking. A Viking who receives a task may pass it on to any Viking that the first one can pass tasks to.

We say that Viking yy is under Viking xx if a task from Viking xx can reach Viking yy.

Hiccup finds this scheme too complicated and inefficient, so he wants to introduce a new one. The new scheme has exactly one leader, to whom nobody can pass a task. Every Viking other than the leader receives tasks from exactly one other Viking. Tasks from the leader must be able to reach every Viking in the village. In other words, the new scheme is a rooted tree with edges directed away from the root. Hiccup also wants the set of Vikings under each Viking xx to be the same in the new scheme and in the old one, for every xx.

Hiccup has not been able to find such a scheme. Determine whether one exists, and if it does, find any one of them.

Input

The first line contains two integers nn and mm, the number of Vikings and the number of pairs in the old scheme (1≤n,m≤5000001 \le n, m \le 500000).

Each of the next mm lines contains a pair of integers aia_i, bib_i, meaning that in the old scheme the aia_i-th Viking can pass a task to the bib_i-th Viking (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i). The same pair may appear more than once.

Output

If the required scheme does not exist, print No.

Otherwise, print Yes on the first line. On the second line, print nn integers p1,p2,…,pnp_1, p_2, \ldots, p_n. If the ii-th Viking is the leader of the new scheme, then pi=−1p_i = -1. Otherwise, pip_i is the number of the Viking who passes tasks to the ii-th Viking in the new scheme (1≤pi≤n1 \le p_i \le n, i≠pii \ne p_i).

Examples1

  1. Example 1

    Input
    3 3
    1 2
    2 3
    1 3
    
    Expected output
    Yes
    -1 1 2