Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:该题根本不用并查集。树的性质。。附AC代码，，

Posted by ryanliu at 2017-12-06 16:14:12 on Problem 1308
In Reply To:该题根本不用并查集。树的性质。。附AC代码，， Posted by:lvweihua at 2017-08-12 19:49:31
```> /*水题，根本用不着并查集。。。树的性质：结点的个数==边的个数+1  空树的时候单独判断就行了。。23333333333
> */
> #include<cstdio>     //顶点的个数==边的个数+1
> #include<cstring>
> const int MAXN=1000000;
> int par[MAXN];
> int main()
> {
>     int m,n;
>     int t=1;
>     while(scanf("%d%d",&m,&n)&&m>=0&&n>=0){
>         memset(par,0,sizeof(par));
>         int e=1;
>         if((m==0&&n==0)){   //空树
>             printf("Case %d is a tree.\n",t++);
>             continue;
>         }
>         par[m]=par[n]=1;
>         while(scanf("%d%d",&m,&n)&&m>0&&n>0){
>             e++;
>             par[m]=par[n]=1;
>         }
>         int v=0;
>         for(int i=0;i<MAXN;i++)
>             v+=par[i];
>         int flag=(v==e+1);
>         printf("Case %d ",t++);
>         if(flag)
>             puts("is a tree.");
>         else
>             puts("is not a tree.");
>     }
>     return 0;
> }
```

Followed by: