Arctic Network
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 18447 |
|
Accepted: 5829 |
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).
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
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5#include <cmath>6 using namespacestd;7 intt,n,tot,fa[510],x,y;8 Const intinf=0x7fffffff;9 DoubleSt:250005];Ten intmark=0; One structdian{ A Doublex, y; -}node[510]; - structedge{ the intU,v;DoubleW; -}e[250005]; - voidAdd_edge (intUintVDoubleW) { -e[tot].u=u;e[tot].v=v;e[tot].w=w;tot++; + } - BOOLCMP (Edge A,edge b) { + returna.w<B.W; A } at voidinit () { -memset (fa,-1,sizeof(FA)); -tot=0; - } - intFindintx) { - if(fa[x]==-1)returnx; in Else returnfa[x]=find (Fa[x]); - } to voidKruskal (intN) { + Doubleans=0; -Sort (e,e+tot,cmp); the intCnt=0; * for(intk=0; k<tot;k++){ $ intu=e[k].u,v=e[k].v;Panax Notoginseng intRx=find (u), ry=Find (v); - if(rx!=ry) { thert[mark]=e[k].w;ans+=E[K].W; +fa[rx]=ry;mark++;cnt++; A } the if(cnt = = N1) Break; + } - //if (cnt<n-1) return-1; $ //else return ans; $ } - intMain () - { thescanf"%d", &t);ints; - while(t--){Wuyi init (); thescanf"%d%d",&s,&n); - for(intI=1; i<=n;i++) Wuscanf"%LF%LF",&node[i].x,&node[i].y); - for(intI=1; i<=n;i++){ About DoubleD; $ for(intj=1; j<=i;j++){ - if(I==J) {d=INF;} - Else{ -D=SQRT (1.0* (node[i].x-node[j].x) * A(node[i].x-node[j].x) ++1.0* (node[i].y-node[j].y) the* (node[i].y-node[j].y)); - } $ Add_edge (i,j,d); the } the } the Kruskal (n); theprintf"%.2f\n", rt[mark-s]); - } in return 0; the}
The night of essay finally AC.
POJ 2349 Arctic Network