[Kuangbin take you to fly] Thematic six minimum spanning tree G - Arctic Network

G - Arctic Network

Topic links: https://vjudge.net/contest/66965#problem/G

topic:

Ministry of National Defense (DND) wants to connect several northern outpost over the wireless network. When it is established using two different communication techniques: Each outpost has a radio transceiver, and a satellite channel number outpost.
    Outpost any two satellite channels can communicate via satellite, regardless of its position. Otherwise, two sentinel only when the distance between them does not exceed D can communicate by radio, depending on the power of the transceiver. Higher power produces a higher D but higher costs. Since the procurement and maintenance considerations outpost transceivers must be the same; that is to say, D values for each of the outposts are the same.

    Your job is to determine the minimum required D. transceiver There must be at least a communication path between each sentinel (directly or indirectly).
Input
    The first input line comprises N, i.e. 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, i.e., the number of sentinel. Line following P, is given for each sentinel (x, y) coordinates, in units of km (coordinate is an integer between 0 and 10,000).
Yield
    for each case, the output should be on one line, the desired network analysis should be specified as the minimum output D. 2 periods.
Sample input

    . 1
    2. 4
    0 100
    0 300
    0 600
    150 750

Sample Output

    212.13

Thinking: s communication tools, P points, the first minimum spanning tree, and then use the array CUN [] of each side of the minimum spanning tree save up, since the minimum requirements D, so s communication to the longest tool s sides, is necessary to use the rest of the radio transceiver, so the output cun [ps-1] can be due to index from zero, so that a reduction, do not open the array as well as small, will wa.

 

//
// Created by hanyu on 2019/7/31.
//
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
struct Node{
    int u,v;
    double w;
    bool operator<(const Node &other)const{
        return this->w<other.w;
    }
}node[maxn];
int father[maxn];
double cun[maxn];
int find(int x)
{
    if(x==father[x])
        return x;
    return father[x]=find(father[x]);
}
double len(double x1,double x2,double y1,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        double xx[maxn],yy[maxn];
        for(int i=0;i<=m;i++)
            father[i]=i;
        memset(cun,0,sizeof(cun));
        for(int i=1;i<=m;i++)
        {
            scanf("%lf%lf",&xx[i],&yy[i]);
        }
        int cnt=0;
        for(int i=1;i<m;i++)
        {
            for(int j=i+1;j<=m;j++)
            {
                double p=len(xx[i],xx[j],yy[i],yy[j]);
                node[cnt].u=i;
                node[cnt].v=j;
                node[cnt++].w=p;
            }
        }
        sort(node,node+cnt);
        int book=0;
        for(int i=0;i<cnt;i++)
        {
            int uu=find(node[i].u);
            int vv=find(node[i].v);
            if(uu==vv)
                continue;
            else
            {
                father[uu]=vv;
                cun[book++]=node[i].w;
            }
        }
        printf("%.2f\n"with [MN- 1 ]); 
    } 
    Return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/11279848.html