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 Elysium at 2006-10-13 00:21:18 on Problem 2492
#include <iostream>

int bug[2000];
int mergecount,bugcount;

inline void init(void)
{
	for(int i=0;i<bugcount;++i)
		bug[i]=i;
}

int find(int x)
{
	if(x!=bug[x])
		bug[x]=find(bug[x]);
	return bug[x];
}

bool merge(int x,int y)
{
	static int xx,yy;
	
	xx=find(x);
	yy=find(y);
	if(xx==yy)
		return false;
	bug[yy]=xx;
	return true;
}

int main(void)
{
	int round,r;
	int i,x,y;
	bool state;

	scanf("%d",&round);
	for(r=1;r<=round;++r)
	{
		scanf("%d %d",&bugcount,&mergecount);
		init();
		state=true;
		if(1==bugcount)
			state=false;
		while(mergecount--)
		{
			scanf("%d %d",&x,&y);
			if(state)
				state=merge(x,y);
		}
		if(1==bugcount)
			state=true;
		printf("Scenario #%d:\n",r);
		if(state)
			printf("No suspicious bugs found!\n");
		else
			printf("Suspicious bugs found!\n");
		if(r!=round)
			printf("\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