0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:48:48 +00:00

P3388 【模板】割点(割顶)

P3388 【模板】割点(割顶)
This commit is contained in:
Baoshuo Ren 2022-01-03 19:40:03 +08:00
parent 31edb8e601
commit 72624c0e4d
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

62
Luogu/P3388/P3388.cpp Normal file
View File

@ -0,0 +1,62 @@
#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;
}