1192 Java
\tclass Solution {\n\t\tpublic List> criticalConnections(int n, List> connections) {\n\t\t\tint[] seen = new int[n];\n\t\t\tint[] low = new int[n];\n\t\t\tArray
\tclass Solution {\n\t\tpublic List<List<Integer>> criticalConnections(int n, List<List<Integer>> connections) {\n\t\t\tint[] seen = new int[n];\n\t\t\tint[] low = new int[n];\n\t\t\tArrays.fill(seen, -1);\n\t\t\tList<Integer>[] graph = new ArrayList[n];\n\t\t\tList<List<Integer>> res = new ArrayList<>();\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tgraph[i] = new ArrayList<>();\n\t\t\t}\n\n\t\t\tint len = connections.size();\n\t\t\t// graph\n\t\t\tfor (int i = 0; i < len; i++) {\n\t\t\t\t// p -> q\n\t\t\t\tint p = connections.get(i).get(0);\n\t\t\t\tint q = connections.get(i).get(1);\n\t\t\t\tgraph[p].add(q);\n\t\t\t\tgraph[q].add(p);\n\t\t\t}\n\n\t\t\t// not seen, dfs\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (seen[i] == -1) {\n\t\t\t\t\tdfs(i, low, seen, graph, res, 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tint time = 0;\n\t\tprivate void dfs(int u, int[] low, int[] seen, List<Integer>[] graph, List<List<Integer>> res, int node) {\n\t\t\tseen[u] = low[u] = ++time;\n\t\t\tfor (int j = 0; j < graph[u].size(); j++) {\n\t\t\t\tint v = graph[u].get(j);\n\t\t\t\tif (v == node) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (seen[v] == -1) {\n\t\t\t\t\tdfs(v, low, seen, graph, res, u);\n\t\t\t\t\tlow[u] = Math.min(low[u], low[v]);\n\t\t\t\t\tif (low[v] > seen[u]) {\n\t\t\t\t\t\tres.add(Arrays.asList(u, v));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlow[u] = Math.min(low[u], seen[v]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}
[]