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

Re:案例能过...就是WA..快疯了...大牛帮看看吧..T T

Posted by 22201232261 at 2013-05-12 14:39:10 on Problem 1703
In Reply To:案例能过...就是WA..快疯了...大牛帮看看吧..T T Posted by:a65982021 at 2012-08-02 11:22:59
> #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:
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