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

做2395AC的代码改了下~~为什么到这里是WA~~~

Posted by jeepyutian at 2009-04-10 14:19:00 on Problem 2377
#include <iostream>
#include <string.h>

using namespace std;

struct node
{
	int x,y;
	int len;
}num[20005];

int cmp(const void *a,const void *b)
{
	
    struct node*c = (node *)a;
    struct node*d = (node *)b;
    return d->len - c->len;
}

int p[1008];

int Find_set(int x)
{
	if(x != p[x])
	{
		p[x] = Find_set(p[x]);
	}
	return p[x];
}

void Make_set(int x)
{
	int i;
	for(i=0; i<x; i++)
	{
		p[i] = i;
	}
}

int main()
{
	__int64 sum;
	int N,M;
	int i;
	cin>>N>>M;
	for(i=0; i<M; i++)
	{
		cin>>num[i].x>>num[i].y>>num[i].len;
	}
	qsort(num,M,sizeof(num[0]),cmp);
	Make_set(N);
	sum=0;
	for(i=0; i<M; i++)
	{	
		if(Find_set (p[num[i].x]) != Find_set (p[num[i].y]))
		{
		
			sum += num[i].len;
			p[Find_set(num[i].x)] = p[Find_set(num[i].y)];
		}
	}
	printf("%I64d", 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