This problem is equivalent to Minimal Labels from Codeforces. Treat the "label" of a vertex in "Minimal Labels" as the completion time of a course in "Course Schedule II." So it suffices to solve the CF problem (editorial) and then output the inverse permutation.
Implementation
Time Complexity:
import heapqn, m = map(int, input().split())out = [0] * (n + 1) # Number of outgoing nodesradj = [[] for _ in range(n + 1)] # Reverse graphfor _ in range(m):a, b = map(int, input().split())radj[b].append(a)out[a] += 1
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!