Poj2349arctic Network (minimum spanning tree kruscal+ K-long Edge)

Source: Internet
Author: User

Topic Links:ah haha, dot me dot Me
Test Instructions:
A region of the Arctic has n villages (1≤n≤500), each of which is represented by a pair of integers (x, y), of which 0≤x, y≤10000. In order to strengthen linkages, it was decided to establish communication networks between villages. The communication tool can be a radio transceiver, or it can be a satellite device. All villages can have a radio transceiver, and all radio transceiver models are the same.  But the number of satellite equipment is limited, and only some of the villages are equipped with satellite equipment. Different types of radios have a different parameter d, the distance between the two villages if not more than D can be used in this model of Radio transceiver Direct communication, D value the larger the model price more expensive. Two villages with satellite equipment can communicate directly, no matter how far apart.
The main problem is that the satellite is not good to deal with, but if the front is not good, then you can think from the reverse, if you know the minimum distance d, then remove the minimum spanning tree is greater than the edge of D, then the graph will exist K connected branch, here to a theorem: If the minimum spanning tree is divided into K-connected branches, the graph is divided into K-connected branches. so for each connected branch of a satellite phone can be, then this shortest distance d will be removed greater than D after the largest edge, that is, the K-long edge .... Then the problem is solved ...
Title:
Arctic Network
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 10211 Accepted: 3374

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
Code:
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include < cmath>using namespace Std;const int maxn=500+10;int s,p,root[maxn],cal;double dis[maxn*maxn];struct Point{int x, y;}    point[maxn];struct edge{int u,v; double distance;}    Edge[maxn*maxn];int findroot (int x) {if (root[x]!=x) Root[x]=findroot (root[x]); return root[x];} Double Caldistance (point A,point b) {return sqrt (1.0* (a.x-b.x) * (a.x-b.x) +1.0* (A.Y-B.Y) * (A.Y-B.Y)); BOOL CMP (Edge A,edge b) {return a.distance<b.distance;} BOOL Cmp2 (double a,double b) {return a>b;}    void Kruscal () {memset (dis,0.0,sizeof (dis));    int sum=0,i,k=0;        for (i=1;i<=cal;i++) {int fx=findroot (EDGE[I].U);        int Fy=findroot (EDGE[I].V);        if (fx==fy) continue;            else {root[fx]=fy;            sum++;            Dis[sum]=edge[i].distance;        if (sum==p-1) break; }} sort (dis+1,dis+1+sum,cmp2); printf ("%.2f\n", Dis[s]);}    void Read_graph () {for (int i=1;i<=p;i++) root[i]=i;    for (int i=1;i<=p;i++) scanf ("%d%d", &point[i].x,&point[i].y);        for (int i=1;i<p;i++) for (int j=i+1;j<=p;+j++) {double temp=caldistance (point[i],point[j]);        Edge[++cal].u=i;        Edge[cal].v=j;    Edge[cal].distance=temp; } sort (edge+1,edge+1+cal,cmp);}    int main () {int t;    scanf ("%d", &t);        while (t--) {cal=0;        scanf ("%d%d", &s,&p);        Read_graph ();    Kruscal (); } return 0;}


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.