Topological sorting.