| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
who can check this code for me ?it's confusing....i always got Runtime Error.....#include<stdio.h>
#include<string.h>
int f[100010],d[100010];
int find(int v)
{
int t;
if(f[v]==-1)return v;
t=find(f[v]);
d[v]+=d[f[v]];
return f[v]=t;
}
int main()
{
int test,cnt;
char name[10];
int len;
int a,b,x,y;
//freopen("in","r",stdin);
scanf("%d",&test);
while(test-->0)
{
scanf("%d%d",&len,&cnt);
for(int i=0;i<=len;i++)f[i]=-1,d[i]=0;
while(cnt-->0)
{
scanf("%s%d%d",name,&a,&b);
x=find(a),y=find(b);
if(name[0]=='A')
{
if(x==y)
printf("%s\n",(d[a]-d[b])%2!=0? "In different gangs.":"In the same gang.");
else
printf("Not sure yet.\n");
}else if(name[0]=='D')
{
f[y]=x;
d[y]=d[a]-d[b]+1;
}
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator