Same setup as Course Schedule: n courses and prerequisite pairs a b (take b before a). Return a valid order to take all courses; among valid orders return the lexicographically smallest. If impossible, print -1.
Input
n ma bOutput: the order, space-separated — or -1.
2 1 1 0
0 1
4 4 1 0 2 0 3 1 3 2
0 1 2 3
2 2 1 0 0 1
-1
Run your code against the sample tests, or Submit to run the full suite.