-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10369.cpp
78 lines (74 loc) · 1.42 KB
/
10369.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
10369 - Arctic Network
*/
#include<bits/stdc++.h>
using namespace std;
#define MX 505
vector<pair<double,pair<int,int> > >p;
vector<int>parent(MX);
int x[MX],y[MX];
int size_;
void set_value(int n)
{
for(int i=0; i<n; i++)
{
parent[i]=i;
}
size_=n;
}
int findd(int i)
{
return (parent[i]==i)?i:findd(parent[i]);
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t;
cin>>t;
while(t--)
{
int node,edge;
cin>>node>>edge;
for(int i=0; i<edge; i++)
{
cin>>x[i]>>y[i];
}
set_value(edge);
p.clear();
for(int i=0; i<edge; i++)
{
for(int j=i+1; j<edge; j++)
{
double distance = sqrt((x[i]-x[j])*(x[i]-x[j])*1.0+(y[i]-y[j])*(y[i]-y[j])*1.0);
p.push_back(make_pair(distance,make_pair(i,j)));
}
}
sort(p.begin(),p.end());
double ans = 0.0;
for(int i=0; size_>node; i++)
{
int px = findd(p[i].second.first);
int py = findd(p[i].second.second);
if(px!=py)
{
ans = max(ans,p[i].first);
parent[px]=py;
size_--;
}
}
cout<<fixed<<setprecision(2)<<ans<<endl;
}
return 0;
}
/*
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
*/