답안 #376236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376236 2021-03-11T05:33:10 Z lyc Odašiljači (COCI20_odasiljaci) C++14
70 / 70
57 ms 8172 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;
typedef tuple<ll,int,int> edge;
#define SQ(x) (((ll)x)*(x))

const int mxN = 1005;
const int mxE = 500005;

int N, X[mxN], Y[mxN];
edge el[mxE];

struct DSU {
    int *rt, *sz, comp;
    DSU(int n) {
        rt = new int[n] - 1;
        sz = new int[n] - 1;
        comp = n;
        FOR(i,1,n){
            rt[i] = i;
            sz[i] = 1;
        }
    }

    int finds(int i) { return (rt[i] == i) ? i : (rt[i] = finds(rt[i])); }

    bool unions(int i, int j) {
        int x = finds(i), y = finds(j);
        if (x != y) {
            if (sz[x] < sz[y]) swap(x,y);
            sz[x] += sz[y];
            rt[y] = x;
            --comp;
            return 1;
        } return 0;
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> N;
    FOR(i,1,N){
        cin >> X[i] >> Y[i];
    }

    int e = 0;
    FOR(i,1,N){
        FOR(j,i+1,N){
            el[e++] = edge(SQ(X[i]-X[j])+SQ(Y[i]-Y[j]), i, j);
        }
    }

    sort(el, el+e);
    DSU dsu(N);
    FOR(i,0,e-1){
        dsu.unions(get<1>(el[i]), get<2>(el[i]));
        if (dsu.comp == 1) {
            cout << fixed << setprecision(7) << sqrt(get<0>(el[i]))/2 << '\n';
            return 0;
        }
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 16 ms 2284 KB Output is correct
7 Correct 16 ms 2284 KB Output is correct
8 Correct 37 ms 4716 KB Output is correct
9 Correct 57 ms 8172 KB Output is correct
10 Correct 56 ms 8172 KB Output is correct