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 |
何以不过??wa的让人不可原谅啊#include<iostream> #include<string.h> #include<memory.h> #include<stdio.h> using namespace std; int parent[40000]; int find(int x) { if(parent[x]<0)return x; else find(parent[x]); } void Union(int root1,int root2) { int x=find(root1); int y=find(root2); if(x==y)return; if(parent[x]<=parent[y]) { parent[x]+=parent[y]; parent[y]=x; } else { parent[y]+=parent[x]; parent[x]=y; } } int main() { int ti,zu,n,y,x,num; int i,j,k; while(scanf("%d%d",&ti,&zu)!=EOF) { if(ti==0&&zu==0)break; for(i=0;i<ti;i++) parent[i]=-1; for(i=0;i<zu;i++) { scanf("%d",&n); if(n)scanf("%d",&x); for(j=1;j<n;j++) { scanf("%d",&y); Union(x,y); } } cout<<0-parent[find(0)]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator