| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求救哪位帮帮忙 谢谢
#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator