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

大牛帮帮忙!看看哪错了,WA一上午了!泪狂甩啊 ~~~~

Posted by baolijuncool at 2011-05-09 12:05:49 on Problem 1703
#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:
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