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

Posted by ChenXiXing at 2005-04-11 15:15:30 on Problem 2377
#define debug 0
#define NMAX 1004
#define INF 10000000
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int a[NMAX][NMAX]={0};
int d[NMAX]={0};
int flag[NMAX]={0};
int N,M;
void solve()
{
	int i,j;
	int tmax=0;
	for(i=1;i<=N;i++)
	{
		d[i]=a[1][i];
	}
	flag[1]=1;
	int dmax;
	for(i=2;i<=N;i++)
	{
		dmax=0;
		int index=-1;
		for(j=2;j<=N;j++)
		{
			if(flag[j])
				continue;
			if(dmax<d[j])
			{
				dmax=d[j];
				index=j;
			}
		}
		if(dmax==0)
			for(int k=0;k<=100000000;k++);
		tmax+=dmax;
		flag[index]=1;
		for(j=1;j<=N;j++)
		{
			if(flag[j])
				continue;
			if(d[j]<a[index][j])
				d[j]=a[index][j];
		}
	}
	printf("%d",tmax);

}
main()
{
#if debug 	
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%d%d",&N,&M);
	int i,j;
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			a[i][j]=0;
	int A,B,C;
	for(i=1;i<=M;i++)
	{
		scanf("%d%d%d",&A,&B,&C);
		if(a[A][B]<C)
			a[A][B]=C;
			a[B][A]=C;
	}
	int flag=0;
	for(i=1;i<=N;i++)
	{
		flag=0;
		for(j=1;j<=N;j++)
		{
			if(a[i][j])
				flag=1;
		}
		if(flag==0)
		{
			printf("-1\n");
			return 1;
		}
	}
	solve();
#if debug
	fclose(stdin);
	fclose(stdout);
#endif;
	return 1;
}

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