求助
查看原帖
求助
973480
封禁用户楼主2024/8/8 17:13
#include<iostream>
using namespace std;
const int maxn=100001;
int n,m,e[maxn][maxn],root;
int num[maxn],low[maxn],flag[maxn],index;
int min(int a,int b){
    return a < b ? a : b;
}
void dfs(int cur,int father){
    int child=0,i;
    index++;
    num[cur]=index;
    low[cur]=index;
    for(i=1;i<=n;i++){
        if(e[cur][i]==1){
            if(num[i]==0){
                child++;
                dfs(i,cur);
                low[cur]=min(low[cur],low[i]);
                if(cur!=root&&low[i]>=num[cur]) flag[cur]=1;
                if(cur==root&&child==2) flag[cur]=1;
            }else if(i!=father){
                low[cur]=min(low[cur],num[i]);
            }
        }
    }
    return;
}
int main(){
	int i,j,x,y;
	cin >> n >> m;
	for(i=1;i<=n;i++){
	    for(j=1;j<=n;j++){
	        e[i][j]=0;
	    }
	}
	for(i=1;i<=m;i++){
	    cin >> x >> y;
	    e[x][y]=1;
	    e[y][x]=1;
	}
	root=1;
    int ans=0;
	dfs(1,root);
    for(i=1;i<=n;i++){
	    if(flag[i]==1) ans++;
	}
    cout << ans << endl;
	for(i=1;i<=n;i++){
	    if(flag[i]==1) cout << i << " ";
	}
	return 0;
}
2024/8/8 17:13
加载中...