Professor Byte wants the smallest-numbered available course taught first, while respecting prerequisites. Print that deterministic course order, or -1 if a prerequisite cycle makes graduation impossible. Input: n m followed by m directed prerequisite pairs a b (a must precede b), vertices 1..n. Output: lexicographically smallest valid order, or -1.
Example 1:
Example 2:
Example 3:
Constraints:
1≤n≤200000; 0≤m≤300000.
Tags:
