283. Topological Order
MediumTopological Sort
The directed graph is acyclic. Print a topological order; when several nodes are available, always take the smallest numbered one (so the answer is unique).
Input format
Line 1: n m Next m lines: u v (u must come before v)
Output format
n node numbers.
Example 1
Input
4 3 1 2 1 3 3 4
Output
1 2 3 4
Example 2
Input
3 0
Output
1 2 3
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…