#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#endif
using namespace std;
const bool __initialization = []() {
cin.tie(nullptr)->sync_with_stdio(false);
#define TASK "ANGTEN"
if (fopen(TASK".inp", "r")) {
(void)(!freopen(TASK".inp", "r", stdin));
(void)(!freopen(TASK".out", "w", stdout)); }
cout << setprecision(12) << fixed;
return true;
}();
using ll = long long;
using ld = long double;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)
template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }
constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
// =============================================================================
constexpr int maxn = 1000 + 5;
struct Pt { int x, y; };
struct Edge {
int u, v; ld c;
bool operator<(const Edge& o) const {
return c < o.c;
}
};
int n;
Pt a[maxn];
Edge e[maxn * maxn];
int ptr;
int par[maxn];
int find(int x) {
return (par[x] < 0) ? x : (par[x] = find(par[x]));
}
bool merge(int u, int v) {
u = find(u); v = find(v);
if (u == v) return false;
if (par[v] < par[u]) swap(u, v);
par[u] += par[v];
par[v] = u;
return true;
}
ll sqr(ll x) {
return x * x;
}
ld calc(int i, int j) {
return sqrt(sqr(a[i].x - a[j].x) + sqr(a[i].y - a[j].y));
}
signed main() {
cin >> n;
For (i, 1, n) cin >> a[i].x >> a[i].y;
For (i, 1, n - 1) {
For (j, i + 1, n ) {
e[ptr++] = {i, j, calc(i, j)};
}
}
sort(e, e + ptr);
memset(par + 1, -1, sizeof(int) * n);
ld ans = 0;
Rep (i, ptr) {
if (merge(e[i].u, e[i].v)) {
ans = e[i].c;
}
}
cout << ans / 2 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
14 ms |
4236 KB |
Output is correct |
7 |
Correct |
16 ms |
4172 KB |
Output is correct |
8 |
Correct |
35 ms |
9036 KB |
Output is correct |
9 |
Correct |
83 ms |
15948 KB |
Output is correct |
10 |
Correct |
78 ms |
15972 KB |
Output is correct |