topsort works for graph a