dependency graph with topological sorting