Topological Sorting solved by 303

Feb. 21, 2014, 5:37 p.m. by Rosalind Team

Topics: Graphs

Problem

Given: A simple directed acyclic graph with $n \le 10^3$ vertices in the edge list format.

Return: A topological sorting (i.e., a permutation of vertices) of the graph.

Sample Dataset

4 5
1 2
3 1
3 2
4 3
4 2

Sample Output

4 3 1 2

Visualization

Visualization by David Galles: http://www.cs.usfca.edu/~galles/visualization/ConnectedComponent.html.

Please login to solve this problem.