#P1333. Uniqueness of Topological Order

Uniqueness of Topological Order

Uniqueness of Topological Order

题目描述

This is a problem given in the Graduate Entrance Exam in 2023: Given a directed graph G, you are supposed to tell if there exists a unique topological order of its vertices.

输入格式

Each input file contains one test case. For each case, the first line gives two positive integers n(104)n (≤10^4), the number of vertices in the graph, and m(105)m (≤10^5), the number of directed edges. Then mm lines follow, each gives the start and the end vertices of an edge. The vertices are numbered from 11 to nn. It is guaranteed that no duplicated edge is given.

输出格式

Output the vertices with the smallest in-degree in the first line, in ascending order. Then if there exists a unique topological order of all the vertices, first print in a line Yes and then output the topological sequence in the next line. Or if the answer is no, just print in a line No. All the numbers in a line must be separated by exactly 11 space, and there must be no extra space at the beginning or the end of the line.

样例 #1

样例输入 #1

6 9
2 1
1 3
5 2
5 4
2 3
2 6
3 4
6 4
6 1

样例输出 #1

5
Yes
5 2 6 1 3 4