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

坑~~如果在同一集合中,就不能建关系否则ML或者TML

Posted by 1871168524 at 2014-10-31 02:09:08 on Problem 1703
坑~~如果在同一集合中,就不能建关系否则ML或者TML

WA的注意两个人时,不管啥操作,两人一定是不属于一个组织的。
下面是正确的代码附上!!!


#include<stdio.h>
int gx[100005],mark[100005];
int find(int p)
{
	int temp=gx[p];
	if(p!=gx[p])
	{
	   gx[p]=find(gx[p]);
	   mark[p]+=mark[temp];
	   mark[p]%=2;
	}
	return gx[p];
}
int main()
{
	int T,i,p,q,n,m,t1,t2;
	char ch;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		for(i=0;i<=n;i++)
		{
			gx[i]=i;
			mark[i]=0;
		}
		while(m--)
		{
			getchar();
			scanf("%c",&ch);
			if(ch=='A')
			{
				scanf("%d%d",&p,&q);
				if(n==2&&p!=q)
				{
				   printf("In different gangs.\n");
				   continue;
			    }
				t1=find(p);
				t2=find(q);
				if(t1!=t2) printf("Not sure yet.\n");
				else
				{
					if(mark[p]%2==mark[q]%2) printf("In the same gang.\n");
					else printf("In different gangs.\n"); 
				}
			}
			if(ch=='D')
			{
				scanf("%d%d",&p,&q);
				t1=find(p);
				t2=find(q);
				if(t1==t2) continue;
				gx[t1]=t2;
			    if(mark[p]==mark[q]) mark[t1]=1;
			    else mark[t1]=0;
			}
		}
	}
	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