# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
908933 | 2024-01-17T02:29:26 Z | Sandarach151 | Odašiljači (COCI20_odasiljaci) | C++17 | 0 ms | 0 KB |
#include<iostream> #include<algorithm> #include<vector> using namespace std; vector<int> link, sze; struct Edge{ int node1; int node2; long double weight; Edge(int a, int b, long double c){ node1=a; node2=b; weight=c; } }; bool operator<(const Edge& a, const Edge& b){ return a.weight<b.weight; } int find(int x){ while(x!=link[x]) x = link[x]; return x; } bool same(int a, int b){ return find(a)==find(b); } void unite(int a, int b){ if(sze[a]<sze[b]) swap(a, b); link[b]=a; sze[a]+=sze[b]; } int main(){ int n; cin >> n; pair<long double, long double> arr[n]; for(int i=0; i<n; i++){ cin >> arr[i].first >> arr[i].second; } link.assign(n, 0); sze.assign(n, 1); for(int i=0; i<n; i++) link[i]=i; vector<Edge> vect; for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ Edge temp(i, j, sqrt(pow(arr[i].first-arr[j].first, 2)+pow(arr[i].second-arr[j].second, 2))/2); vect.push_back(temp); } } sort(vect.begin(), vect.end()); // for(Edge edge : vect){ // cout << edge.node1 << ", " << edge.node2 << ": " << edge.weight << '\n'; // } int cnt = 0; long double minn = 0; for(int pos = 0; pos<vect.size() && cnt<n-1; pos++){ if(!same(vect[pos].node1, vect[pos].node2)){ unite(vect[pos].node1, vect[pos].node2); minn = vect[pos].weight; cnt++; } } cout << minn << '\n'; return 0; }