求割点
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e4+10;
ll n,m,dfn[N],low[N],tot,root;
bool cut[N];
vector<ll> G[N];
void tarjan(ll u){
dfn[u]=low[u]=++tot;
ll flag=0;
for(auto v:G[u]){
if(!dfn[v]){
tarjan(v),low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
flag++;
if(u!=root||flag>1)cut[u]=true;
}
}else low[u]=min(low[u],dfn[v]);
}
}
int main(){
cin >> n >> m;
for(ll i=1;i<=m;i++){
ll u,v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
for(ll i=1;i<=n;i++)if(!dfn[i])root=i,tarjan(i);
vector<ll> ans;
for(ll i=1;i<=n;i++)if(cut[i])ans.push_back(i);
cout << ans.size() << endl;
for(auto i:ans)cout << i << ' ';
return 0;
}
标签:tarjan,连通性,ll,问题,flag,dfn,low
From: https://www.cnblogs.com/ningziang/p/17984486