Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

跪求人帮我看看我的代码为什么总是WA,如果能cha组数据也同样感谢

Posted by lst at 2009-08-27 14:00:25 on Problem 1611
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator