Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位大牛能看看我错在哪里吗?实在不知道怎么搞得?

Posted by luyade at 2008-01-04 23:28:56 on Problem 1703 and last updated at 2008-01-04 23:31:22
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator