Arctic Network (poj 2349 min spanning Tree)

Source: Internet
Author: User

Language:DefaultArctic Network
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 12397 Accepted: 4053

Description

The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Different communication technologies is to being used in establishing the Network:every outpost would have a radio trans Ceiver and some outposts would in addition has a satellite channel.
Any-outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, 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 is identical; That's, 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 is 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 all test case contains 1 <= s <=, the number of satellite channels, and S < P <=, t He number of outposts. P lines follow, giving the (x, y) coordinates of each outpost in km (coordinates is 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 is specified to 2 decimal points.

Sample Input

12 40 1000 3000 600150 750

Sample Output

212.13

Source

Waterloo Local 2002.09.28


Test instructions: There are p outposts, now want to connect them into a whole (that is, the smallest spanning tree), there are two ways to connect (1) satellite connection, as long as two outposts have a satellite, they can communicate (2) to transmit radio, but there is a certain cost, proportional to the distance. Minimum cost (i.e. the maximum of all distances in the radio communication)

Idea: First use Kruskal to find the smallest spanning tree, the longer side uses the satellite to communicate, then the answer is Ans[p-1-s]. Oh, this code on the POJ to use C + + to cross before, do not know how to ...

Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define PI ACOs ( -1.0) #define EPS 1e-6# Define Lson rt<<1,l,mid#define Rson rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A; I <= b; i++) #define FREE ( I,A,B) for (i = A, I >= b; i--) #define FRL (i,a,b) for (i = A; I < b; i++) #define FRLL (i,a,b) for (i = A; i > b; i-- ) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d",         &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF Printf#define DBG PF ("hi\n") typedef long long ll;using namespace std; #define INF 0x3f3f3f3f#define mod 1000000009const int maxn = 555;const int MAXN = 2005;const int MAXM = 300010;const int N = 1005;struct node{double x, y;}    node[maxn];struct edge{int u,v; Double Len;}    EDGE[MAXM];d ouble ans[maxn];int s,p,cnt;int father[maxn];void init () {cnt=0; for (int i=0;i<=p;i++) father[i]=i;} int CMP (Edge e1,edge E2) {return e1.len<e2.len;} Double Dis (Node n1,node n2) {return sqrt ((n1.x-n2.x) * (n1.x-n2.x) + (N1.Y-N2.Y) * (N1.Y-N2.Y));}    int find_father (int x) {if (x!=father[x]) Father[x]=find_father (father[x]); return father[x];}    Double Kruskal () {int i,j;    Sort (edge,edge+cnt,cmp);    int num=0;        for (i=0;i<cnt;i++) {int fu=find_father (EDGE[I].U);        int Fv=find_father (EDGE[I].V);            if (FU!=FV) {FATHER[FU]=FV;            Ans[num++]=edge[i].len;        if (num==p-1) break; }} return ans[num-s];}    int main () {#ifndef Online_judge freopen ("C:/users/lyf/desktop/in.txt", "R", stdin), #endif int i,j,t;    SF (t);        while (t--) {SFF (s,p);        Init (); for (i=1;i<=p;i++) scanf ("%lf%lf", &node[i].x,&node[i].y);                for (i=1;i<=p;i++) {for (j=i+1;j<=p;j++) {if (i==j) continue;                Edge[cnt].u=i;                Edge[cnt].v=j;            Edge[cnt++].len=dis (Node[i],node[j]);    }} printf ("%.2lf\n", Kruskal ()); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Arctic Network (poj 2349 min spanning Tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.