Skip to content
C

Topological Sort

Mediumjavapythonccppjavascript

Given a directed acyclic graph, return the lexicographically smallest topological ordering of its vertices — an ordering in which, for every directed edge u -> v, u comes before v, and among all such orderings the one that is smallest when compared position by position.

Input Format

The first line contains two integers V and E. Each of the next E lines contains a directed edge u v.

Output Format

Print the lexicographically smallest topological ordering, vertices separated by single spaces.

Input (stdin)

Output

Run your code to see output here...