POJ 2349 Arctic Network

Source: Internet
Author: User

Minimum spanning tree K small edge problem.


Test instructions is said to have n points, there are two ways to connect, satellite and wireless, satellite free to connect, unlimited need to configure the receiver, the receiver price and acceptable distance is the same.

The satellite frequency is limited and has m channels.

That is to say, build the smallest spanning tree, front n-1-m side with wireless, behind M side with satellite.


Use an array to save the cost for each time, and the final output is good.


#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <queue> #include <map> #include <stack> #include <iostream> #include <list># include<set> #include <cmath> #define INF 0x7fffffff#define eps 1e-6using namespace std;int n,m;int fa[501];    struct lx{int u,v; Double Len;} L[501*250];struct node{double x, y;}    Point[501];int father (int x) {if (x!=fa[x]) Fa[x]=father (fa[x]); return fa[x];} BOOL CMP (LX A,lx b) {return a.len<b.len;}    int main () {int t;    scanf ("%d", &t);        while (t--) {scanf ("%d%d", &m,&n);        for (int i=0;i<=n;i++) fa[i]=i;        for (int i=1;i<=n;i++) scanf ("%lf%lf", &point[i].x,&point[i].y);        int cot=0;            for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) {l[cot].u=i;            L[cot].v=j; L[cot++].len=sqrt (Pow (point[i].x-point[j].x,2) +pow (point[i].y-point[j].y,2));        } sort (l,l+cot,cmp);        Double path[501];        int pcot=1;            for (int i=0;i<cot;i++) {int fu=father (L[I].U);            int Fv=father (L[I].V);            if (FU==FV) continue;            Fa[fv]=fu;        Path[pcot++]=l[i].len;    } printf ("%.2f\n", path[pcot-m]); }}


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.