#include<cstdio> #include<iostream> #include<cstring> #include<vector> using namespace std; inline int read(){ int num=0,t=1;char c=getchar(); while(c>'9'||c<'0'){if(c=='-')t=-1;c=getchar();} while(c<='9'&&c>='0'){num=num*10+c-'0';c=getchar();} return num*t; } const int N=500010; int dfn[N],low[N],t=0,n,m; bool dian[N],bian[N]; struct edge{int t,num;}; vector<edge> g[N]; void dfs(int x,int fa){ int child=0,tmp;dfn[x]=low[x]=++t; for(int i=0;i<g[x].size();i++){ int y=g[x][i].t;if(y==fa){tmp=i;continue;} if(!dfn[y]){ child++;dfs(y,x); low[x]=min(low[x],low[y]); if(low[y]>=dfn[x])dian[x]=1; } else low[x]=min(low[x],dfn[y]); } if(low[x]==dfn[x]&&fa!=-1)bian[g[x][tmp].num]=1; if(fa==-1&&child<=1)dian[x]=0; } int main() { n=read();m=read(); for(int i=1;i<=m;i++){ int x=read(),y=read(); g[x].push_back((edge){y,i}); g[y].push_back((edge){x,i}); } for(int i=1;i<=n;i++) if(!dfn[i])dfs(i,-1); for(int i=1;i<=n;i++) if(dian[i])printf("%d ",i); puts(""); for(int i=1;i<=m;i++) if(bian[i])printf("%d ",i); return 0; }
本文由Yzyet编写,网址为www.cnblogs.com/Yzyet。非Yzyet同意,禁止转载,侵权者必究。