链接三维空间中n个点的最短距离 最小生成树(krukal算法)

DESCRIPTION

Spoon Devil build a 3-D matrix, and he(orshe) wants to know if he builds some bases what's the shortest distance toconnect all of them.

INPUT

There are multiple test cases. The firstline of input contains an integer T, indicating the number of test cases. Foreach test case:

The first line contains one integern (0

OUTPUT

For each test case, output a line, whichshould accurately rounded to two decimals.

SAMPLE INPUT

2

2

1 1 0

2 2 0

3

1 2 3

0 0 0

1 1 1

SAMPLE OUTPUT

1.41

3.97

 题意

求连n个点(三维坐标),所需要的最短距离。(最小生成树)

1.首先对点做预处理2.用krukal算法进行求解。

#include 
#include 
#include 
int n,m;
double s;
int p[1005];
struct ed{
		int u;
		int v;
		double w;
	};
struct asd{
	int x;
	int y;
	int z;
};
struct ed e[5000];
int find (int x)
{
	return p[x]==x?x:p[x]=find(p[x]);
}
void kru()
{
	int i,j,x,y;
	for(i=1;i<=m;i++)
	{
		x=find(e[i].u);
		y=find(e[i].v);
		if(x!=y)
		{
			p[x]=y;
			s=s+e[i].w;
		}
	}
}

void sort()
{
	int i,j,k;
	struct ed t;
	for(i=1;i<=m-1;i++)
	{
		k=i;
		for(j=i+1;j<=m;j++)
		if(e[j].w



你可能感兴趣的:(树)