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,如果能cha组数据也同样感谢#include <stdio.h> #include <algorithm> using namespace std; int a[30010]; struct node { int x; int fa; }shu[30010]; int main() { int i,j,n,m,t,x,sum; while(scanf("%d%d",&n,&m),!(n==0&&m==0)) { if(n==0) { printf("0\n"); continue; } sum=0; for(i=0;i<n;i++) { shu[i].x=i; shu[i].fa=i; } for(i=0;i<m;i++) { scanf("%d",&t); for(j=0;j<t;j++) { scanf("%d",&a[j]); } sort(a,a+t); for(j=0;j<t;j++) { shu[a[j]].x=a[j]; if(shu[a[j]].fa>=a[0]) shu[a[j]].fa=a[0]; } } for(i=0;i<n;i++) { j=i; while(shu[j].fa!=shu[j].x) { j=shu[j].fa; } if(j==0) sum++; } printf("%d\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator