Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 3833 | Accepted: 1389 |
Description
Input
Output
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
#include <iostream> #include <cstdio> #include <vector> #include <cstring> #include <queue> #include <cmath> #include <algorithm> using namespace std; const int MAXN=510; struct cpoint { double x; double y; }point[MAXN]; const int INF=100000000; struct node { int to; double w; node(int _to=0,double _w=INF) { to=_to; w=_w; } }edge[MAXN]; bool operator<(const node &e1,const node &e2) { return e1.w>e2.w; } int main() { int t; scanf("%d",&t); int p; int i,j; int sub; int s; int visit[MAXN]; node dist[MAXN];//the minimum distance of one vertex to the tree double ans[MAXN]; while(t--) { priority_queue<node> qu; vector<node> cmap[MAXN]; scanf("%d %d",&s,&p); for(i=1;i<=p;i++) { scanf("%lf %lf",&point[i].x,&point[i].y); } memset(visit,0,sizeof(visit)); for(i=0;i<=p;i++) { dist[i].to=i; dist[i].w=INF; } node xmap; for(i=1;i<=p;i++) { sub=0; for(j=1;j<=p;j++) { xmap.to=j; xmap.w=sqrt((point[i].x-point[j].x)*(point[i].x-point[j].x)+(point[i].y-point[j].y)*(point[i].y-point[j].y)); cmap[i].push_back(xmap); } } qu.push(node(1,0)); int sum=p; node current; int AnsIndex=0; while(sum--) { do { current=qu.top(); qu.pop(); }while(visit[current.to]==true&&!qu.empty()); if(visit[current.to]==false) { visit[current.to]=true; ans[AnsIndex++]=current.w; for(i=0;i<cmap[current.to].size();i++)//for each v belong to Adj[current.to] { if(visit[cmap[current.to][i].to]==false) { if(cmap[current.to][i].w<dist[cmap[current.to][i].to].w) { dist[cmap[current.to][i].to].w=cmap[current.to][i].w; qu.push(dist[cmap[current.to][i].to]); } } } } } sort(&ans[1],&ans[p]); if(p<=s) { printf("0.00/n"); } else { printf("%.2f/n",ans[p-s]); } } return 0; }