UVA 10369 section K edge on Arctic Network minimum spanning tree

Source: Internet
Author: User

At first it was wrong to think that it must be the adjacency point to use the satellite signal, so it started wrong several times! Later read the online statement just know not directly to find out s-1 big side on it! (actually still don't understand test instructions)


#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack > #include <cstdlib> #include <cmath> #include <set> #include <map> #include <vector># Include <cstring> #define INF 100000000using namespace Std;int x[1005];int y[1005];int vis[1005];int fa[1005]; struct Node{int X,y,w;bool operator < (const node &a) Const{return W < A.W;} BOOL operator > (const node &a) Const{return w > a.w;}}; int fun (int x) {return fa[x] ==x x:fun (fa[x]);} int main () {int t;scanf ("%d", &t), while (t--) {int s,p;cin >> s >> p;for (int i = 0;i < p;i++) {cin >> X[i] >> y[i];} priority_queue<node,vector<node>,greater<node> > que;for (int i = 0;i < p;i++) {for (int j = 0;j < P; J + +) {if (i! = j) {Node a;a.x = I;A.Y = J;A.W = (X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]); Que.push (a);}}} for (int i = 0;i < p;i++) {Fa[i] = i;} Priority_queue<node,vector<node>,less<node> > Ant;while (!que.empty ()) {Node A = Que.top (), Que.pop (), int fx = Fun (a.x), int fy = fun (A.Y); if (FX! = FY) {FA [FX] =fy;ant.push (a);}} memset (vis,0,sizeof (VIS)); while (S > 1) {Node A = Ant.top (); s--;ant.pop ();} Node A = Ant.top ();p rintf ("%.2f\n", sqrt (A.W));} return 0;}


UVA 10369 section K edge on 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.