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 AlexLashield at 2015-05-21 13:25:40 on Problem 1308
//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:
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