답안 #496109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496109 2021-12-20T16:56:52 Z AlperenT Odašiljači (COCI20_odasiljaci) C++17
70 / 70
452 ms 336 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;

int n;

pair<int, int> arr[N];

long double l, r, m, x, y;

struct DSU{
    int par[N], stsize[N], setcnt;

    void reset(int n){
        for(int i = 1; i <= n; i++) par[i] = i, stsize[i] = 1;
        setcnt = n;
    }

    int setfind(int a){
        if(par[a] == a) return a;
        else return par[a] = setfind(par[a]);
    }

    void setunion(int a, int b){
        a = setfind(a), b = setfind(b);

        if(a != b){
            if(stsize[b] > stsize[a]) swap(a, b);
            par[b] = par[a];
            stsize[a] += stsize[b];
            setcnt--;
        }
    }
};

DSU dsu;

bool check(long double m){
    dsu.reset(n);

    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            x = abs(arr[i].first - arr[j].first), y = abs(arr[i].second - arr[j].second);

            if(m >= sqrt(x * x + y * y) / 2) dsu.setunion(i, j);
        }
    }

    return dsu.setcnt == 1;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n;

    for(int i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second;

    l = 0 - 1e-9, r = 1e12;

    for(int i = 0; i < 100; i++){
        m = l + (r - l) / 2;

        if(check(m)) r = m;
        else l = m;
    }

    cout << setprecision(12) << r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 113 ms 208 KB Output is correct
7 Correct 121 ms 328 KB Output is correct
8 Correct 264 ms 336 KB Output is correct
9 Correct 433 ms 336 KB Output is correct
10 Correct 452 ms 332 KB Output is correct