标签:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 13108 | Accepted: 4256 |
Description
Input
Output
Sample Input
1 2 4 0 100 0 300 0 600 150 750
Sample Output
212.13
Source
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; const int MAXN=1000+5; int kase,n,m; double ans[MAXN*MAXN/2]; int p[MAXN]; struct node { double x,y; }po[MAXN]; struct edge { int u,v; double val; bool operator<(const edge A)const { return val<A.val; } }a[MAXN*MAXN/2]; double calc(node A,node B) { return sqrt( (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y) ); } int findfa(int x) { return p[x]==x?x:p[x]=findfa(p[x]); } int main() { //freopen("in.txt","r",stdin); scanf("%d",&kase); while(kase--) { scanf("%d %d",&n,&m); for(int i=1;i<=m;i++) scanf("%lf %lf",&po[i].x,&po[i].y); int cnt=1; for(int i=1;i<=m;i++) { for(int j=1;j<=m;j++) { a[cnt].u=i; a[cnt].v=j; a[cnt++].val=calc(po[i],po[j]); } } sort(a+1,a+1+cnt); for(int i=1;i<=m;i++) p[i]=i; int res=0; for(int i=1;i<=cnt;i++) { int u=a[i].u; int v=a[i].v; int x=findfa(u); int y=findfa(v); if(x!=y) { p[x]=y; ans[res++]=a[i].val; if(res==m-1) break; } } if(n==0) printf("%.2lf\n",ans[res-1]); else printf("%.2lf\n",ans[res-n]); } return 0; }
POJ 2349 Arctic Network (最小生成树第K大(小)边)
标签:
原文地址:http://www.cnblogs.com/clliff/p/4709389.html