lexographic topo sort