"UVA 10369" Arctic Network (minimum spanning tree)

Source: Internet
Author: User

Test instructions

  There are n scientific stations in Antarctica that connect these stations with satellites or radios so that any two of them can be connected directly or indirectly. Any two of them are equipped with satellite equipment and can be directly via satellite communications, no matter how far away they are. and two stations with radio equipment, the distance cannot exceed D. D The longer the cost the more.

Now there's a satellite device that can be installed, and there are enough radios to find a solution that makes the cost D at least (d depends on the path that spends most of the radio communication).

Input
The first line of input contains N, the number of test cases. The first line of all 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 miles (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
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13

Analysis

If there is no satellite device, then the minimum spanning tree is straightforward.

If the satellite equipment >=2, then can isolate s-1 area to come out (put the satellite equipment there, leaving a device in the big group inside)

The equivalent of the tree's s-1 edge is set to 0,

That is of course the smallest spanning tree after the S-1 large edge is set to 0.

The process of krutal can calculate the result directly.

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <queue>7#include <cmath>8 using namespacestd;9 #defineMAXN 510Ten  One structnode A { -     intx, y; -     DoubleC; the}T[MAXN*MAXN];intLen; -  - intNX[MAXN],NY[MAXN]; -  + voidInsintXintYDoublec) - { +T[++len].x=x;t[len].y=y;t[len].c=C; A } at  - BOOLCMP (node X,node y) {returnx.c<y.c;} -  - intFA[MAXN]; - intFFAintx) - { in     if(X!=fa[x]) fa[x]=FFA (Fa[x]); -     returnFa[x]; to } +  - intMain () the { *     intT; $scanf"%d",&T);Panax Notoginseng      while(t--) -     { the         ints,p; +scanf"%d%d",&s,&p); A          for(intI=1; i<=p;i++) scanf ("%d%d",&nx[i],&ny[i]); thelen=0; +          for(intI=1; i<=p;i++) -           for(intj=i+1; j<=p;j++) $          { $              DoubleXx= (Double) (Nx[i]-nx[j]), yy= (Double) (ny[i]-ny[j]); -Ins (I,j,sqrt (xx*xx+yy*yy)); -          } theSort (t+1, t+1+len,cmp); -         intCnt=0;Wuyi          for(intI=1; i<=p;i++) fa[i]=i; the         if(p==s) printf ("0.00\n"); -         Else Wu         { -              for(intI=1; i<=len;i++) About             { $                 if(FFA (t[i].x)! =FFA (T[I].Y)) -                 { -Fa[ffa (t[i].x)]=FFA (T[I].Y); -cnt++; A                     if(cnt==p-s) {printf ("%.2lf\n", T[I].C); Break;} +                 } the             } -         } $          the     } the     return 0;  the}
View Code

2016-11-01 16:35:05

"UVA 10369" Arctic Network (minimum 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.