private void ifNotDagThrowException(Digraph g) {
   DirectedCycle cycle = new DirectedCycle(g);
   if (cycle.hasCycle() || !isOnlyOneRoot(g)) throw new IllegalArgumentException();
 }