Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define F(W) for(int i(0);i<W;++i)
- #define FF(W) for(int j(0);j<W;++j)
- #define FT(I,W) for(int k(I);k<W;++k)
- #define ZERO (1e-10)
- #define EPS ZERO
- #define INF (1<<30)
- #define LINF (1LL<<60)
- #define NINF (-(1<<30))
- #define MP(A,B) make_pair(A,B)
- #define CL(A,I) (memset(A,I,sizeof(A)))
- #define ADD(A,B,V) (g[A].push_back(B),g[B].push_back(A),v[A].push_back(V),v[B].push_back(V))
- #define add(A,B) (g[A].push_back(B),g[B].push_back(A))
- #define DEB printf("DEB!\n");
- #define DEX printf("DD2!\n");
- #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef vector<int> vi;
- typedef pair<int, int> ii;
- #define REP(i, n) for (int i = 0; i < n; i++)
- #define IN(n) int n; cin >> n;
- #define PB push_back
- #define MX (512)
- double dst(double AX,double AY,double BX,double BY){
- return sqrt(pow(AX-BX,2)+pow(AY-BY,2));
- }
- double x[MX],y[MX];
- int tt,K,N;
- struct eg{
- eg(int f,int t,double v):f(f),t(t),v(v){}
- int f,t;
- double v;
- bool operator<(const eg&r)const{return v>r.v;}
- };
- priority_queue<eg> q;
- int W[MX],C[MX];
- void rc(int c,int t){
- W[t]+=W[c];
- W[c]=-1;
- C[c]=t;
- }
- int geco(int a){
- return a==C[a]?a:geco(C[a]);
- }
- bool con(int a,int b){
- C[a]=geco(a);C[b]=geco(b);
- if(C[a]==C[b])return 0;
- rc(C[b],C[a]);
- return 1;
- }
- double st(int H){
- double S(0);
- while(H--){
- con(q.top().f,q.top().t);
- S=q.top().v;
- while(!q.empty()&&geco(q.top().f)==geco(q.top().t))q.pop();
- }
- while(!q.empty())q.pop();
- return S;
- }
- int main(void){
- for(scanf("%d",&tt);tt--;){
- scanf("%d%d",&K,&N);
- F(N)scanf("%lf%lf",x+i,y+i);
- F(N)FT(i+1,N)q.push(eg(i,k,dst(x[i],y[i],x[k],y[k])));
- iota(C,C+N,0);CL(W,0);
- if(K<=1)printf("%.2lf\n",st(N-1));
- else printf("%.2lf\n",st(N-K));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement