P3388【模板】割点(割顶)
https://www.luogu.com.cn/problem/P3388
求割点模板
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<cmath>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
#include<set>
typedef long long ll;
using namespace std;
const int N = 1e5+5;
int low[N], num[N], dfn;
bool iscut[N];
int ans = 0;
int r = 0;
vector<int>G[N];
void dfs(int u, int fa)
{
low[u] = num[u] = ++dfn;
int child = 0;
for (int i = 0; i < G[u].size(); i++)
{
int v = G[u][i];
if (!num[v])
{
child++;
dfs(v, u);
low[u] = min(low[v], low[u]);
if (low[v] >= num[u] and u != r)
{
iscut[u] = true;
}
}
else low[u] = min(low[u], num[v]);
}
if (u == r and child >= 2)
{
iscut[u] = 1;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int x, y; cin >> x >> y;
G[x].push_back(y), G[y].push_back(x);
}
for(int i=1;i<=n;i++)
if(!num[i])
{
r = i;
dfs(i, i);
}
for (int i = 1; i <= n; i++)if (iscut[i])ans++;
cout << ans << endl;
for (int i = 1; i <= n; i++)if (iscut[i])cout << i << ' ';
return 0;
}