POJ 2349 Arctic Network

Source: Internet
Author: User

1#include <iostream>2#include <cmath>3#include <algorithm>4#include <cstdio>5 using namespacestd;6 #defineMAXN 6007 intPAR[MAXN];8 intPos;9 intn,cnt,m;Ten DoubleLen; One DoubleTT[MAXN];//the path of the saved selection A structnode - { -     intx; the     inty; -     DoubleW; - }; -Node E[MAXN * (MAXN-1) /2]; + intcmpConstNode &a,ConstNode &b) - { +     returnA.W <B.W; A }; at structP - { -     intx; -     inty; - } PO[MAXN]; - voidInit () in { -      for(inti =0; I <= n+5; i++) toPar[i] =i; +pos =0; -Len =0.0; theCNT =0; * } $ intFind (intx)Panax Notoginseng { -     intK,j,r; theR =x; +      while(Par[r]! =R) AR =Par[r]; theK =x; +      while(k! =R) -     { $j =Par[k]; $PAR[K] =R; -K =J; -     } the     returnR; - }Wuyi intMerge (intXinty) the { -     intA =Find (x); Wu     intb =Find (y); -     if(A! =b) About     { $Par[a] =Par[b]; -         return 1; -     } -     return 0; A } + voidinput () the { -     intu,v; $      for(inti =1; I <= N; i++) thescanf"%d%d",&po[i].x,&po[i].y); the } the  the voidMake () - { in init (); the     DoubleDist; the      for(inti =1; I < n; i++) About     { the          for(intj = i +1; J <= N; J + +) the         { theDist = (po[i].x-po[j].x) * (po[i].x-po[j].x) + (PO[I].Y-PO[J].Y) * (PO[I].Y-po[j].y); +e[pos].x =i; -E[POS].Y =J; theE[POS].W =sqrt (dist);Bayipos++; the         } the     } -Sort (e,e+pos,cmp); -      for(inti =0; I < POS; i++) the     { the         if(Merge (E[I].X,E[I].Y)) the         { theTT[CNT] =E[I].W; -cnt++; the         } the         if(cnt = = N-1) Break; the     }94 } the intMain () the { theFreopen ("Input.txt","R", stdin);98     intT; Aboutscanf"%d",&t); -      while(t--)101     {102scanf"%d%d",&m,&n);103 input ();104 Make (); theprintf"%.2lf\n", tt[cnt-m]);106     }107 108     return 0;109}

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.