master topsort