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

P3388 【模板】割点(割顶)

https://www.luogu.com.cn/record/91855549
This commit is contained in:
Baoshuo Ren 2022-10-28 11:03:46 +08:00
parent e93b52517e
commit d7c1104f8b
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -1,23 +1,22 @@
#include <iostream> #include <iostream>
#include <algorithm>
#include <vector> #include <vector>
using std::cin; using std::cin;
using std::cout; using std::cout;
using std::endl; const char endl = '\n';
const int N = 20005; const int N = 2e4 + 5;
int n, m, x, y; int n, m;
std::vector<int> ans, g[N]; std::vector<int> g[N];
int root, cnt, dfn[N], low[N];
// Tarjan
int cnt, dfn[N], low[N];
int root;
bool cut[N]; bool cut[N];
void tarjan(int u) { void tarjan(int u) {
dfn[u] = low[u] = ++cnt; dfn[u] = low[u] = ++cnt;
bool flag = false; bool flag = false;
for (int v : g[u]) { for (int v : g[u]) {
if (!dfn[v]) { if (!dfn[v]) {
tarjan(v); tarjan(v);
@ -36,27 +35,34 @@ void tarjan(int u) {
} }
int main() { int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m; cin >> n >> m;
for (int i = 1; i <= m; i++) {
for (int i = 1, x, y; i <= m; i++) {
cin >> x >> y; cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x); g[x].emplace_back(y);
g[y].emplace_back(x);
} }
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
if (!dfn[i]) { if (!dfn[i]) {
root = i; root = i;
tarjan(i); tarjan(i);
} }
} }
cout << std::count(cut + 1, cut + n + 1, true) << endl;
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
if (cut[i]) { if (cut[i]) {
ans.push_back(i);
}
}
cout << ans.size() << endl;
for (int i : ans) {
cout << i << ' '; cout << i << ' ';
} }
}
cout << endl; cout << endl;
return 0; return 0;
} }