@Test public void testSolveDAG() { int N = 200; Random r = new Random(); for (int i = 5; i < N; i += r.nextInt(5)) { Digraph dag = DigraphGenerator.dag(i, r.nextInt(i * (i - 1) / 2)); TransitiveClosure tc = new TransitiveClosure(dag); int test = ReachableVertex.solveDAG(GraphConverter.convert(dag)); if (test == -1) { Assert.assertTrue(checkNoThatPoint(tc, i)); } else { Assert.assertTrue(checkThatPoint(tc, test, i)); } } }
public static int solveDAG(Set<Integer>[] dag) { int ans = -1, n = dag.length; for (int i = 0; i < n; i++) { if (dag[i].isEmpty()) { if (ans != -1) return -1; ans = i; } } return ans; }
ReachableVertex { public static int solveDAG(Set<Integer>[] dag) { int ans = -1, n = dag.length; for (int i = 0; i < n; i++) { if (dag[i].isEmpty()) { if (ans != -1) return -1; ans = i; } } return ans; } }
ReachableVertex { public static int solveDAG(Set<Integer>[] dag) { int ans = -1, n = dag.length; for (int i = 0; i < n; i++) { if (dag[i].isEmpty()) { if (ans != -1) return -1; ans = i; } } return ans; }  }
ReachableVertex { public static int solveDAG(Set<Integer>[] dag) { int ans = -1, n = dag.length; for (int i = 0; i < n; i++) { if (dag[i].isEmpty()) { if (ans != -1) return -1; ans = i; } } return ans; }  static int solveDAG(Set<Integer>[] dag); static int solveDigraph(Set<Integer>[] digraph); }
ReachableVertex { public static int solveDAG(Set<Integer>[] dag) { int ans = -1, n = dag.length; for (int i = 0; i < n; i++) { if (dag[i].isEmpty()) { if (ans != -1) return -1; ans = i; } } return ans; }  static int solveDAG(Set<Integer>[] dag); static int solveDigraph(Set<Integer>[] digraph);  }