$P1991 無線通訊網$
阿新 • • 發佈:2019-04-20
https pri find fine tps lin pro -s digi
\(problem\)
// luogu-judger-enable-o2 #include <bits/stdc++.h> #define Max(a,b) a>b?a:b using namespace std ; typedef long long LL ; inline LL read() { LL x(0); register char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=(x<<1)+(x<<3)+(c&15),c=getchar(); return x; } using namespace std; const int N=505; struct P1{ int t1,t2; double v; }line[N*N]; struct po{ double x,y; }st[N]; int s,p,num,fa[N];double ans; inline double dis(int x1,int y1){ return sqrt((st[x1].x-st[y1].x)* (st[x1].x-st[y1].x)+ (st[x1].y-st[y1].y)* (st[x1].y-st[y1].y)); } inline bool cmp(P1 x,P1 y){ return x.v<y.v; } inline int find(int x){ return fa[x] == x ? fa[x] : fa[x] = find (fa[x]) ; } inline void unionn(int x,int y) { fa[find(x)] = find(y); } int main(){ s = read() ; p = read() ; for(register int i=1;i<=p;i++) fa[i] = i ; for(register int i=1;i<=p;i++) st[i].x = read() , st[i].y = read(); for(register int i=1;i<=p;i++) for(register int j=i+1;j<=p;j++){ num++; line[num].t1=i; line[num].t2=j; line[num].v=dis(i,j); } sort(line+1,line+num+1,cmp); int a,b; s=p-s; for(register int i=1;i<=num,s>0;i++){ a=line[i].t1; b=line[i].t2; int fx = find(a) , fy = find(b) ; if(fx != fy){ unionn(a,b); s--; ans=Max(ans,line[i].v); } } cout << fixed << setprecision(2) << ans << endl ;//printf("%.2lf",ans); return 0; }
$P1991\ 無線通訊網$