Topological sort on G0 adapted to new structure