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

求救

Posted by lxc0601 at 2007-12-16 09:16:45 on Problem 2492
哪位帮帮忙 谢谢

#include<iostream>
#define maxn 2005
using namespace std;
int parent[maxn];

int findset(int x){
	/*if( x != parent[x] )
		parent[x] = findset( parent[x] );
	return parent[x];*/
	int i;
	 for(i = x; parent[i] !=i; i = parent[i]);//搜索根节点
	 while(i!=x)//路径压缩
	 {
		  int tmp = parent[x];
		  parent[x] = i;
		  x = tmp;
	 }
	 return i;


}
void unio(int i,int j){
	
	int temp;
	temp=parent[i]+parent[j];
	if(parent[i]>parent[j])
	{
		parent[j]=temp;
		parent[i]=j;
	}
	else
	{
		parent[i]=temp;
		parent[j]=i;
	}


}
int main(){
	int cases;
	cin>>cases;

	for(int k=1;k<=cases; k ++)
	{
		int Points,count;
		cin>>Points>>count;
		int a,b;
		int i;
		for(i=1; i<=Points ;i ++ )
			parent[i]=i;
		bool flag=false;

		for( i=1;i<=count; i++ )
		{
			scanf("%d %d",&a,&b);

			//cout<<a<<" "<<b<<endl;
		
			int x=findset(a);
			int y=findset(b);
			if(x==y){
				flag=true;
			
			}
			else
			{
				//parent[x]=y;
				unio(x,y);
			
			}
		}
		cout<<"Scenario #"<<k<<":"<<endl;
		if(flag){
				
				cout<<"Suspicious bugs found!"<<endl;
		}

		
		else	
		{
			cout<<"No suspicious bugs found!"<<endl;
		}
	
		cout<<endl;
	}
	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