#include<cstdio>
#include<cstring>
using
namespace
std;
constintMaxN=3001;
typedefintArr[MaxN];int N
,M,A,B;
intans;
Arre[MaxN],disa,disb,Lw,L;
voidinit()
{ scanf(
"%d%d%d%d",&N
,&M,&A,&B);
memset(
L,0,sizeof(
L));
memset(
Lw,0,sizeof(
Lw));
for(
inti=1;
i<=M;
++i){ intx,y;
scanf(
"%d%d",&x,&y);
L[x]++;
L[y]++;
Lw[x]++;
e[x][Lw[x]]=y;
Lw[y]++;
e[y][Lw[y]]=x;
}}voidgetdis(
int s
,Arr&dis)
{ memset(
dis,0x7F,sizeof(
dis));
inth,t;
Arrque;
h=t=1;
que[1]=s;
dis[s
]=0;
while(
h<=t){ intx=que[h++]; for(
inti=1;
i<=Lw[x];++i){ inty=e[x][i]; if(
dis[y]>dis[x]+1){ dis[y]=dis[x]+1;
que[++t]=y;
} } }}voidcalc()
{ inth,t;
Arrque;
h=1;
t=0;
for(
inti=1;
i<=N;
++i)
if(
L[i]==1)
que[++t]=i;
while(
h<=t){ intx=que[h++]; for(
inti=1;
i<=Lw[x];++i){ inty=e[x][i]; L[y]--;
if(
L[y]==1)
que[++t]=y;
} }}voidsolve()
{ ans=0;
for(
inti=1;
i<=N;
++i)
if(
disb[i]>disa[i]&&L[i]>1){ printf(
"NIE\n");
return;
} elseif(
disb[i]>ans&&disb[i]>disa[i]) ans=disb[i]; printf(
"%d\n",ans);
}intmain()
{ freopen(
"gon.in","r",stdin);
freopen(
"gon.out","w",stdout);
init();
getdis(
A,disa);
getdis(B
,disb);
calc();
solve();
return0;
}
posted on 2009-08-05 21:54
xfstart07 阅读(171)
评论(0) 编辑 收藏 引用