hdu1325

计算每个点的入度。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int vis[maxn],rd[maxn];
int top; 
int main(){
    int x,y;
    while(1){
        scanf("%d%d",&x,&y);
        if(x<=-1&&y<=-1)break;
        top++;
        if(x==0&&y==0){
            puts("Yes");
            continue;
        }
        for(int i=1;i<=1e5;i++)
            vis[i]=rd[i]=0;
        rd[y]++;
        vis[x]=vis[y]=1;
        int ans=0,flag=1;
        while(1){
            scanf("%d%d",&x,&y);
            if(x==0&&y==0)break;
            vis[x]=vis[y]=1;
            rd[y]++;
        }
        for(int i=1;i<=1e5;i++)
            if(vis[i]){
                if(rd[i]>1)flag=0;
                else if(rd[i]==0){
                    if(!ans)ans=1;
                    else flag=0;
                }
            }
        if(flag==1)printf("Case %d is a tree.\n",top);
        else printf("Case %d is not a tree.\n",top);
    }
    return 0;
}

 

posted @ 2020-03-02 09:03  syzf2222  阅读(83)  评论(0编辑  收藏  举报