Improved algorithm to generate a topological ordering
1. Compute the indegrees of all vertices in the graph
2. Place all vertices with indegree 0 in a queue
3. While the queue is not empty, remove a vertex v from the queue, assign it the next topological number, and decrement the indegree of all vertices adjacent to v. If a vertex's indegree falls to 0, enqueue it.
4. If the number of vertices assigned a topological number is not equal to the total number of vertices, the graph has a cycle