-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11266.cpp
More file actions
78 lines (62 loc) · 1.78 KB
/
11266.cpp
File metadata and controls
78 lines (62 loc) · 1.78 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
#include <iostream>
#include <memory.h>
#include <utility>
#include <vector>
#include <stack>
using namespace std;
int V, E, A, B;
vector<int> adj[10000 + 1];
int dfn[10000 + 1], low[10000 + 1], order, bccNum;
bool acPoint[10000 + 1];
vector<pair<int, int>> BCC[10000 + 1];
stack<pair<int, int>> s;
void dfs (int cur, int par) {
dfn[cur] = low[cur] = ++order;
int childCnt = 0;
for (int nxt : adj[cur]) {
if (nxt == par) continue;
if (dfn[nxt] == 0) {
s.push(make_pair(cur, nxt));
childCnt++;
dfs(nxt, cur);
low[cur] = min(low[cur], low[nxt]);
if (dfn[cur] <= low[nxt]) {
if (par != -1) acPoint[cur] = true;
bccNum++;
while (s.top() != make_pair(cur, nxt)) {
BCC[bccNum].push_back(s.top());
s.pop();
}
BCC[bccNum].push_back(s.top());
s.pop();
}
} else if (dfn[cur] > dfn[nxt]) {
low[cur] = min(low[cur], dfn[nxt]);
s.push(make_pair(cur, nxt));
}
}
if (par == -1 && childCnt >= 2) acPoint[cur] = true;
return ;
}
int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> V >> E;
while (E--) {
cin >> A >> B;
adj[A].push_back(B);
adj[B].push_back(A);
}
memset(dfn, 0, sizeof(dfn));
memset(low, 0, sizeof(low));
memset(acPoint, false, sizeof(acPoint));
order = 0, bccNum = 0;
for (int i = 1; i <= V; i++) {
if (dfn[i] == 0) dfs(i, -1);
}
vector<int> ans;
for (int i = 1; i <= V; i++) {
if (acPoint[i]) ans.push_back(i);
}
cout << ans.size() << "\n";
for (int x : ans) cout << x << " ";
return 0;
}