| ||||||||||
| 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..快疯了...大牛帮看看吧..T T#include<iostream>
using namespace std;
int father[200050];
int a,b;
int m,n;
void init(int x)
{
father[x]=x;
}
int find(int x)
{
if(x!=father[x])
{
father[x]=find(father[x]);
}
return father[x];
}
void union_(int a,int b)
{
int aa=find(a);
int bb=find(b);
if(aa!=bb)
//return;
father[aa]=bb;
}
int main()
{
int test;
// int i;
char c;
scanf("%d",&test);
while(test--)
{
scanf("%d%d",&m,&n);
for(int i=1;i<=m*2;i++)
init(i);
for(int j=1;j<=n;j++)
{
scanf("%c%c %d %d",&c,&c,&a,&b);
if(c=='D')
{
union_(a,b+n);
union_(b,a+n);
}
else
{
if(find(a)==find(b))
printf("In the same gang.\n");
else if(find(a)==find(b+n)||find(b)==find(a+n))
printf("In different gangs.\n");
else
printf("Not sure yet.\n");
}
}
}
return 1;
}
/*
1
5 5
A 1 2
D 1 2
A 1 2
D 2 4
A 1 4
*/
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator