# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1152329 | Sandarach151 | Odašiljači (COCI20_odasiljaci) | C++17 | 0 ms | 0 KiB |
#include<iostream>
#include<vector>
#include<tuple>
#include<math>
using namespace std;
vector<pair<long double, pair<int, int> > > vect;
vector<int> sze;
vector<int> lnk;
int find(int a){
while(a!=lnk[a]){
a = lnk[a];
}
return a;
}
bool same(int a, int b){
return find(a)==find(b);
}
void unite(int a, int b){
a = find(a);
b = find(b);
if(sze[a]<sze[b]){
swap(a, b);
}
lnk[b]=a;
sze[a]+=sze[b];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
pair<int, int> points[n];
sze.assign(n, 1);
for(int i=0; i<n; i++){
lnk.push_back(i);
}
for(int i=0; i<n; i++){
int a, b;
cin >> a >> b;
points[i] = make_pair(a, b);
}
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
vect.push_back(make_pair(sqrt(pow(points[i].first-points[j].first, 2) + pow(points[i].second-points[j].second, 2)), make_pair(i, j)));
}
}
sort(vect.begin(), vect.end());
for(int i=0; i<vect.size(); i++){
cout << vect[i].second.first << ' ' << vect[i].second.second << ' ' << vect[i].first << '\n';
}
int cnt = 0;
long double ans = 0;
for(int i=0; i<vect.size(); i++){
int a = vect[i].second.first;
int b = vect[i].second.second;
if(!same(a, b)){
unite(a, b);
cnt += 1;
ans = vect[i].first / 2;
}
if(cnt==n-1) break;
}
cout << ans << '\n';
return 0;
}