0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 22:08:47 +00:00
OI-codes/Luogu/P3388/P3388.cpp
Baoshuo 72624c0e4d
P3388 【模板】割点(割顶)
P3388 【模板】割点(割顶)
2022-01-03 19:40:03 +08:00

63 lines
1.2 KiB
C++

#include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
const int N = 20005;
int n, m, x, y;
std::vector<int> ans, g[N];
// Tarjan
int cnt, dfn[N], low[N];
int root;
bool cut[N];
void tarjan(int u) {
dfn[u] = low[u] = ++cnt;
bool flag = false;
for (int v : g[u]) {
if (!dfn[v]) {
tarjan(v);
low[u] = std::min(low[u], low[v]);
if (dfn[u] <= low[v]) {
if (u != root || flag) {
cut[u] = true;
} else {
flag = true;
}
}
} else {
low[u] = std::min(low[u], dfn[v]);
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 1; i <= n; i++) {
if (!dfn[i]) {
root = i;
tarjan(i);
}
}
for (int i = 1; i <= n; i++) {
if (cut[i]) {
ans.push_back(i);
}
}
cout << ans.size() << endl;
for (int i : ans) {
cout << i << ' ';
}
cout << endl;
return 0;
}