-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10369_Arctic Network.cpp
More file actions
102 lines (85 loc) · 2.12 KB
/
10369_Arctic Network.cpp
File metadata and controls
102 lines (85 loc) · 2.12 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include<bits/stdc++.h>
#define pb(n) push_back(n)
#define bug cout<<"bug";
#define all(c) c.begin(),c.end()
#define fr(i,n) for(i=0;i<n;i++)
#define sf(n) scanf("%d",&n)
#define mst(n) memset(n,0,sizeof(n))
#define nl printf("\n")
#define lli long long int
#define tr(container,it) \
for (auto it = container.begin(); it != container.end() ; ++it)
#define INF INT_MAX
#define MOD 1000000007
#define mp(i,j) make_pair(i,j)
#define mstn(n) memset(n,-1,sizeof(n))
#define infile freopen("in.txt","r",stdin)
#define outfile freopen("out.txt","w",stdout)
#define V 5
using namespace std;
typedef pair<int,int> pi;
int pr[501];
// typical kruskal algorithm application
class edge
{
public:
int a,b;
double wt;
void Set(int x,int y,double w)
{
a=x, b=y, wt=w;
}
bool operator<(const edge& a)
{
return wt<a.wt;
}
};
double mn(double a,double b)
{
return (a<b?a:b);
}
int Find(int ch)
{
return (pr[ch]==ch?ch :pr[ch]=Find(pr[ch]));
}
int main()
{
int test;
sf(test);
while(test--)
{
vector<edge> comp;
int s,p;
scanf("%d %d",&s,&p);
mst(pr);
int ax[p],ay[p];
for(int i=0; i<p; i++)
{
scanf("%d %d",&ax[i],&ay[i]);
pr[i]=i;
for(int j=0; j<i; j++) // finding all possible path among vertices
{
double ds=sqrt((ax[i]-ax[j])*(ax[i]-ax[j])+(ay[i]-ay[j])*(ay[i]-ay[j]));
edge tmp;
tmp.Set(i,j,ds); // forming an edge with vertices indices and weight of the edge
comp.push_back(tmp);
}
}
sort(all(comp));
int cnt=0,i=0;
vector<double> path;
while(cnt!=(p-1-(s-1)))
{
int p1=Find(comp[i].a);
int p2=Find(comp[i].b);
if(p1!=p2)
{
pr[p1]=p2;
path.push_back(comp[i].wt);
cnt++;
}
i++;
}
printf("%.2lf\n",path[cnt-1]);
}
}