| ||||||||||
| 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 | |||||||||
大牛帮帮忙!看看哪错了,WA一上午了!泪狂甩啊 ~~~~#include<iostream>
using namespace std;
int p[100001];
int r[100001];
void st(int n)
{
for(int i=0;i<=n;i++)
{
p[i]=i;
r[i]=0;
}
}
int find(int x)
{
int t;
if(x==p[x])
return x;
t=p[x];
r[x]=(r[t]+1)%2;
p[x]=find(p[x]);
}
void un(int a,int b)
{
int ta=find(a);
int tb=find(b);
if(ta!=tb)
p[ta]=b;
r[a]=(r[ta]+1)%2;
}
int main()
{
int a,b;
char s;
int x,y;
int t;
cin>>t;
while(t--)
{
scanf("%d%d",&a,&b);
st(b);
while(b--)
{
scanf("\n%c%d%d",&s,&x,&y);
if(s=='A')
{
if(find(x)!=find(y))
printf("Not sure yet.\n");
else
{
if(r[x]==r[y])
printf("In the same gang.\n");
else
printf("In different gangs.\n");
}
}
else
{
un(x,y);
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator