| ||||||||||
| 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 | |||||||||
不知道哪里错了//poj 1308
#include<cstdio>
#include<iostream>
#define M 1000005
using namespace std;
int a[M];
int findf(int x)
{
if(a[x] == x)
{
return x;
}
return a[x] = findf(a[x]);
}
bool mag(int x,int y)
{
int fx = findf(x);
int fy = findf(y);
if(fx == fy)
{
return false;
}
a[fx] = fy;
return true;
}
int main()
{
int cas = 0;
int c,b;
for(int i = 0 ; i < M ; i++)
{
a[i] = i;
}
int flag = 1;
while(scanf("%d%d",&c,&b))
{
if(c < 0 && b < 0)
{
break;
}
if(c == 0 && b == 0)
{
cas++;
if(flag)
{
printf("Case %d is a tree.\n",cas);
}
else{
printf("Case %d is not a tree.\n",cas);
}
flag = 1;
for(int i = 0 ; i < M ; i++)
{
a[i] = i;
}
continue;
}
if(!mag(c,b))
{
flag = 0;
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator