Submission #374331

# Submission time Handle Problem Language Result Execution time Memory
374331 2021-03-07T07:49:58 Z topovik Odašiljači (COCI20_odasiljaci) C++14
70 / 70
264 ms 33356 KB
#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

odasiljaci.cpp: In function 'int main()':
odasiljaci.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long double, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int i = 0; i < qur.size(); i++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 4 ms 1000 KB Output is correct
6 Correct 64 ms 8664 KB Output is correct
7 Correct 63 ms 8684 KB Output is correct
8 Correct 160 ms 33348 KB Output is correct
9 Correct 263 ms 33332 KB Output is correct
10 Correct 264 ms 33356 KB Output is correct