Topological sorting using Tarjan's algorithm
