forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1192.js
29 lines (28 loc) · 769 Bytes
/
1192.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var criticalConnections = function(n, connections) {
var g = [], low = Array(n), res = [];
low.fill(0);
for (let con of connections) {
g[con[0]] = g[con[0]] || [];
g[con[1]] = g[con[1]] || [];
g[con[0]].push(con[1]);
g[con[1]].push(con[0]);
}
var dfs=function(cur, v, p) {
var dfn = cur;
low[v] = cur;
for (let i of g[v]) {
if (i != p) {
if (low[i] == 0) {
cur++;
dfs(cur, i, v);
if (low[i] > dfn) {
res.push([i, v]);
}
}
low[v] = Math.min(low[v], low[i]);
}
}
}
dfs(1, 0, -1);
return res;
};