File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ const int N = 1e5 + 5 ;
3
+
4
+ int n;
5
+ int timer;
6
+ int tin[N], low[N];
7
+ bool vis[N], isArticulation[N];
8
+ vector<int > g[N];
9
+
10
+ void dfs (int u, int par)
11
+ {
12
+ vis[u] = 1 ;
13
+ tin[u] = low[u] = ++timer;
14
+ int children = 0 ;
15
+ for (auto &it:g[u])
16
+ {
17
+ if (it == par)
18
+ continue ;
19
+ if (vis[it])
20
+ low[u] = min (low[u], tin[it]);
21
+ else
22
+ {
23
+ dfs (it, u);
24
+ low[u] = min (low[u], low[it]);
25
+ if (low[it] >= tin[u] && par != -1 )
26
+ isArticulation[u] = 1 ;
27
+ children++;
28
+ }
29
+ }
30
+ if (par == -1 && children > 1 )
31
+ isArticulation[u] = 1 ;
32
+ }
33
+
34
+ void articulationPoints ()
35
+ {
36
+ timer = 0 ;
37
+ memset (vis, 0 , sizeof (vis));
38
+ memset (isArticulation, 0 , sizeof (isArticulation));
39
+ memset (tin, -1 , sizeof (tin));
40
+ memset (low, -1 , sizeof (low));
41
+ for (int i = 1 ; i <= n; i++)
42
+ {
43
+ if (!vis[i])
44
+ dfs (i, -1 );
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments