zoj 1914 Arctic Network(最小生成树))

The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel. 

Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.

Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.


Input

The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).


Output

For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.


Sample Input

1
2 4
0 100
0 300
0 600
150 750


Sample Output

212.13

题目大意:

    国防部想在北部的前哨之间建立一个无线网络连接这些前哨。在建立网络时使用了两种不同的通信技术:每个前哨有一个无线电收发器,有一些前哨还有一个卫星频道。
    任何两个拥有卫星频道的前哨之间可以直接通过卫星进行通信,而且卫星通信跟距离和位置无关。否则,两个前哨之间通过无线电收发器进行通信,并且这两个前哨之间的距离不能超过D,这个D值取决于无线电收发器的功率。功率越大,D值也就越大,但是价格也越高。出于对购买费用和维护费用的考虑,所有使用无线电接收器进行通信的前哨的收发器必须相同,即D值相同。
    你的任务是计算无线电收发器D值的最小值,且保证每两个前哨之间至少有一条通信线路(直接或间接地连接这两个前哨)。

     

本题就是,求出最小生成树的时候,顺便记录生成树的权值,然后从小到大排序,选择p-s条边。

#include 
#include 
#include 
#include 
using namespace std;
int Father[110];
struct node
{
    int a;
    int b;
    double w;
};
int cmp(node a,node b)
{
    return a.w>n;
    int x[505];
    int y[505];
    node num[500*500+10];
    while (n--)
    {
        cin>>s>>p;
        for (int i=0; i<=p; i++)
        {
           Father[i]=i;
        }
        for (int i=0; i>x[i]>>y[i];
        }
        int ans=0;
        for (int i=0; i




你可能感兴趣的:(【图论】)