BOJ/C++
단절점
IamToday
2020. 2. 11. 14:42
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
80
81
82
83
84
85
86
87
88
89
|
#include <iostream>
#include <vector>
#define MAXX 10001
using namespace std;
int v, e;
bool ok[MAXX];
int order[MAXX];
vector<int> edge[MAXX];
int low[MAXX];
int z = 1;
int root = 1;
//시작 정점
int dfs(int node) {
low[node] = order[node];
int child = 0;
for (auto i : edge[node]) {
if (order[i]) {
//이미 방문한 노드
low[node] = min(low[node], order[i]);
}
else {
order[i] = z++;
int ret = dfs(i);
child++;
low[node] = min(ret, low[node]);
if (root != node && ret >= order[node]) {
ok[node] = true;
}
if (root == node) {
if (child >= 2) {
ok[node] = true;
}
}
}
}
return low[node];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int v, e;
cin >> v >> e;
for (int i = 0; i < e; i++) {
int a, b;
cin >> a >> b;
edge[a].push_back(b);
edge[b].push_back(a);
}
for (int i = 1; i <= v; i++) {
if (!order[i]) {
order[i] = z++; //방문 순서 기록
root = i;
dfs(i);
}
}
int ans = 0;
vector<int> res;
for (int i = 1; i <= v; i++) {
if (ok[i]) {
ans++;
res.push_back(i);
}
}
cout << ans << '\n';
for (int i = 0; i < res.size(); i++) cout << res[i] << ' ';
cout << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|