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 |
Re:该题根本不用并查集。树的性质。。附AC代码,,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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator