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

为什么 time out ?

Posted by zhujiangjun at 2006-09-05 11:13:37 on Problem 2524
#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:
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