思路:
Tarjan
if(dfn[x]<=low[v[i]]){
if(x!=1)sub[x]++;
else S++;
}
//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1005
using namespace std;
int xx,yy,first[N],next[N*N*2],v[N*N*2],tot,cnt,T,S,sub[N],f,cases;
int dfn[N],low[N],vis[N];
void add(int x,int y){v[tot]=y,next[tot]=first[x],first[x]=tot++;}
void tarjan(int x,int fa){
dfn[x]=low[x]=++cnt;
for(int i=first[x];~i;i=next[i]){
if(!dfn[v[i]]){
tarjan(v[i],x);low[x]=min(low[x],low[v[i]]);
if(dfn[x]<=low[v[i]]){
if(x!=1)sub[x]++;
else S++;
}
}
else low[x]=min(low[x],dfn[v[i]]);
}
}
int main(){
memset(first,-1,sizeof(first));
while(scanf("%d",&xx)&&xx){
st:scanf("%d",&yy);
add(xx,yy),add(yy,xx);
}
tarjan(1,-1);
T=1;
printf("Network #%d\n",++cases);
if(S>1)sub[1]=S-1;
for(int i=1;i<=1000;i++)
if(sub[i])printf(" SPF node %d leaves %d subnets\n",i,sub[i]+1),f=1;
if(!f)puts(" No SPF nodes");
puts("");
scanf("%d",&xx);
if(xx==0)return 0;
else{
tot=cnt=S=f=0;
memset(sub,0,sizeof(sub));
memset(first,-1,sizeof(first));
memset(dfn,0,sizeof(dfn));
memset(vis,0,sizeof(vis));
goto st;
}
}