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 sw1001 at 2011-04-01 21:20:38 on Problem 1182
#include <stdio.h>

int father[50010], relate[50010];

void makeset(int n)
{
	int i;

	for(i=1;i<=n;++i)
	{
		father[i]=i;
		relate[i]=0;
	}

}


int findset(int x)
{
	int t;
	if(x!=father[x])
	{
		t=father[x];
		father[x]=findset(father[x]);
		relate[x]=(relate[x]+relate[t])%3;
	}
	return father[x];
}


void Union(int x, int y, int relat)
{
	int xx, yy;

	xx=findset(x);
	yy=findset(y);

	
	father[yy]=xx;
     relate[yy]=(relate[x]-relate[y]+relat+3)%3;



}

int main()
{
	int N, K, tag, ai ,bi, sum=0, aai, bbi;


	
	makeset(N);

	while(K--)
	{
		scanf("%d%d%d", &tag, &ai, &bi);


		if(ai>N||bi>N||(tag==2&&ai==bi))
		{
			++sum;
			
		}
		else
		{
			aai=findset(ai);
			bbi=findset(bi);

			if((aai==bbi)&&(relate[ai]-relate[bi]+3)%3!=tag-1)
			{
				++sum;
			
			}
			else
				Union(ai, bi, tag);
		}
	}


	printf("%d\n", sum);
	

	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