-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArticulation_Points.cpp
More file actions
79 lines (71 loc) · 1.26 KB
/
Articulation_Points.cpp
File metadata and controls
79 lines (71 loc) · 1.26 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/************ Articulation_Points ************/
#include<stdio.h>
#include<string.h>
#include<vector>
#include<set>
using namespace std;
#define SZ 10005
#define WHITE 0
#define GREY 1
#define BLACK 2
#define Null -1
int tm;
int d[SZ];
int Low[SZ];
int pred[SZ];
int color[SZ];
set<int> S;
vector<int> edges[SZ];
void init(int n){
tm = 0;
S.clear();
for(int i=0; i<=n; i++){
pred[i] = Null;
color[i] = WHITE;
edges[i].clear();
}
}
int MIN(int a, int b){
return (a<b)?a:b;
}
void ArtPt(int v) {
int i, w, cnt=0;
color[v] = GREY;
Low[v] = d[v] = ++tm;
for(i=0; i<edges[v].size(); i++){
w = edges[v][i];
if(color[w] == WHITE) {
pred[w] = v;
ArtPt(w);
cnt++;
if (pred[v] == Null) {
if(cnt==2)S.insert(v);
}else if (Low[w] >= d[v])S.insert(v);
Low[v] = MIN(Low[v], Low[w]);
}else if (w != pred[v]) {
Low[v] = MIN(Low[v], d[w]);
}
}
color[v] = BLACK;
}
int main(){
freopen("input.txt", "r", stdin);
int t, i, n, m, u, v, cs;
scanf("%d", &t);
for(cs=1; cs<=t; cs++){
scanf("%d%d", &n, &m);
init(n);
for(i=0; i<m; i++){
scanf("%d%d", &u, &v);
edges[u].push_back(v);
edges[v].push_back(u);
}
for(i=1; i<=n; i++){
if( color[i]==WHITE ){
ArtPt(i);
}
}
printf("Case %d: %d\n", cs, S.size());
}
return 0;
}