【模板】割点
题目跳转
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
uint8_t buf[1<<20],*p1,*p2;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
ll rd(){
ll x=0,f=1,ch=gc();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=gc();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch-'0');
ch=gc();
}
return x*f;
}
void write(ll x){
if(x<0){
x*=-1;
putchar('-');
}
if(x>9){
write(x/10);
}
putchar(x%10+'0');
}
const ll maxn=2e4+5;
ll n,m,cnt,ans,rt,dfn[maxn],low[maxn];
vector<ll> e[maxn];
bool cut[maxn];
void tarjan(ll x){
dfn[x]=low[x]=++cnt;
ll flag=0;
for(auto y:e[x]){
if(!dfn[y]){
tarjan(y);
low[x]=min(low[x],low[y]);
if(dfn[x]<=low[y]){
flag++;
if((flag>1||x!=rt)&&!cut[x]){
ans++;
cut[x]=true;
}
}
}else{
low[x]=min(low[x],dfn[y]);
}
}
}
int main(){
n=rd();
m=rd();
for(ll i=1;i<=m;i++){
ll u=rd(),v=rd();
e[u].push_back(v);
e[v].push_back(u);
}
for(ll i=1;i<=n;i++){
if(!dfn[i]){
rt=i;
tarjan(i);
}
}
write(ans);
putchar('\n');
for(ll i=1;i<=n;i++){
if(cut[i]){
write(i);
putchar(' ');
}
}
return 0;
}
Goodbye!

浙公网安备 33010602011771号