# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
374331 | topovik | Odašiljači (COCI20_odasiljaci) | C++14 | 264 ms | 33356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N = 1e6 + 100;
const ll oo = 1e9 + 7;
int pred[N], r[N];
ld dist(ld x, ld y, ld x1, ld y1)
{
return sqrt(pow(x - x1, 2) + pow(y - y1, 2));
}
int cmp(int x)
{
if (x == pred[x]) return x;
else return pred[x] = cmp(pred[x]);
}
void unite(int x, int y)
{
if (r[x] > r[y]) pred[y] = x;
else
{
pred[x] = y;
r[y] += (r[x] == r[y]);
}
}
int main()
{
int n;
cin >> n;
ld x[n], y[n];
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
vector <pair<ld, pair<int, int> > > qur;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j) qur.pb({dist(x[i], y[i], x[j], y[j]), {i, j}});
for (int i = 0; i < n; i++) pred[i] = i, r[i] = 0;
sort(qur.begin(), qur.end());
int cn = 0;
cout << setprecision(7) << fixed;
for (int i = 0; i < qur.size(); i++)
{
int x = qur[i].s.f, y = qur[i].s.s;
if (cmp(x) != cmp(y))
{
cn++;
unite(cmp(x), cmp(y));
if (cn == n - 1)
{
cout << (qur[i].f / (ld)2) << endl;
return 0;
}
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |