#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
int to,next;
}e[100000];
int head[10000],pre[10000],low[10000],d[10000],ans[10000];
int cnt,dfs_clock;
bool cmp(int a,int b){
if(ans[a]==ans[b])
return a<b;
else
return ans[a]>ans[b];
}
void add_edge(int from,int to){
e[cnt].to=to;
e[cnt].next=head[from];
head[from]=cnt++;
}
int dfs(int u,int v){
low[u]=pre[u]=++dfs_clock;
int num=0;
for(int i=head[u];i!=-1;i=e[i].next){
int to=e[i].to;
if(to==v)
continue;
if(!pre[to]){
num++;
int t=dfs(to,u);
low[u]=min(low[u],t);
if(low[to]>=pre[u])
ans[u]++;
}
else if(pre[to]<pre[u] && to != v){
low[u]=min(low[u],pre[to]);
}
}
if(v < 0 && num == 1) ans[u]=1;
return low[u];
}
int main(){
int n,m,a,b;
while(scanf("%d%d",&n,&m) && (n+m)){
memset(head,-1,sizeof(head));
cnt=0;
while(scanf("%d%d",&a,&b) && (a!=-1 || b!=-1)){
add_edge(a,b);
add_edge(b,a);
}
dfs_clock=0;
memset(pre,0,sizeof(pre));
for(int i=0;i<n;i++){
d[i]=i;
ans[i]=1;
}
dfs(0,-1);
sort(d,d+n,cmp);
for(int i=0;i<m;i++)
printf("%d %d\n",d[i],ans[d[i]]);
printf("\n");
}
}
uva 10765 (求去掉每一个一个点 可以得到联通块的个数 )
最新推荐文章于 2023-01-08 12:49:15 发布