Use topological order sorting.