| ||||||||||
| 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 | |||||||||
哪位大牛能看看我错在哪里吗?实在不知道怎么搞得?#include<iostream>
using namespace std;
#define MAXN 100005
int Friend[MAXN],e[MAXN];
int find(int x)
{
int par=x,q;
while(Friend[par]!=par)par=Friend[par];
while(x!=par)
{
q=Friend[x];
Friend[x]=par;
x=q;
}
return par;
}
void Union(int a,int b)
{
Friend[b]=Friend[a];
}
int main()
{
int a,b,i,j,num,m,n;
char str[10];
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d%d",&n,&m);
memset(e,-1,sizeof(e));
for(i=1;i<=n;i++)
Friend[i]=i;
for(j=0;j<m;j++)
{
scanf("%s%d%d",str,&a,&b);
if(str[0]=='D')
{
if(e[a]==-1)
{
e[a]=b;
if(e[b]!=-1)Union(a,e[b]);
}
else
{
if(e[b]==-1)e[b]=a;
Union(b,e[a]);
}
if(e[b]==-1)
{
e[b]=a;
if(e[a]!=-1)Union(b,e[a]);
}
else
{
if(e[a]==-1)e[a]=b;
Union(a,e[b]);
}
}
else
{
if(find(a)==find(b))
printf("In the same gang.\n");
else if(find(a)==find(e[b])||find(e[a])==find(b))
printf("In different gangs.\n");
else printf("Not sure yet.\n");
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator