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 |
为什么 time out ?#include<stdio.h> int sum[50001]; int parent[50001]; int answer[10000]; void find(int n) { int i=n; int mm=n; do{ i=mm; mm=parent[mm]; }while(mm!=-1); sum[i]=1; } main() { int n,m,i,a,b,s=0,num=1; scanf("%d %d",&n,&m); while(n!=0) { for(i=1;i<=n;i++) parent[i]=-1; for(i=1;i<=n;i++) sum[i]=0; for(i=0;i<m;i++) { scanf("%d %d",&a,&b); if(a<b) parent[b]=a; else parent[a]=b; } for(i=1;i<=n;i++) find(i); for(i=1;i<=n;i++) if(sum[i]==1) s++; printf("Case %d: %d\n",num,s); answer[num]=s; s=0; num++; scanf("%d %d",&n,&m); } //for(i=1;i<num;i++) //printf("Case %d: %d\n",i,answer[i]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator