K. 2024春-A-4 Uniqueness of Topological Order

    传统题 150ms 64MiB

2024春-A-4 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 nn (104\le 10^4), the number of vertices in the graph, and mm (105\le 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 1 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 1 space, and there must be no extra space at the beginning or the end of the line.

样例

6 9
2 1
1 3
5 2
5 4
2 3
2 6
3 4
6 4
6 1
5
Yes
5 2 6 1 3 4
6 8
1 2
1 3
5 2
5 4
2 3
2 6
3 4
6 4
1 5
No

限制

对于所有的测试用例,限制为150 ms, 64 MB

PAT2024春季重现赛

未参加
状态
已结束
规则
IOI
题目
11
开始于
2025-8-17 14:00
结束于
2025-8-17 17:30
持续时间
3.5 小时
主持人
参赛人数
46