Submission #1102656

# Submission time Handle Problem Language Result Execution time Memory
1102656 2024-10-18T15:04:25 Z huantran Odašiljači (COCI20_odasiljaci) C++17
0 / 70
2 ms 340 KB
#include <bits/stdc++.h>
// #define bit(x, i) 

using namespace std;
const int maxn = 1e3 + 5;
typedef long double ll; 

int n;
vector<tuple<ll, ll, ll>> edge;
vector<tuple<ll, ll, ll>> point;
int par[maxn];

ll dis(ll a, ll b, ll c, ll d) {
    return sqrt((a - c)*(a - c) + (b - d)*(b - d));
}

int find_par(int u) {
    return (u == par[u]) ? u : par[u] = find_par(par[u]);
}

void make_union(int u) {
    par[u] = u;
}

int merge_union(int u, int v) {
    u = find_par(u);
    v = find_par(v);

    if (u == v) {
        return false;
    }

    par[u] = v;
    return true;
}

int main() {
     #ifndef ONLINE_JUDGE
        freopen("TASK.inp", "r", stdin);
        freopen("TASK.out", "w", stdout);
    #endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin >> n;

    for (int i = 1; i <= n; i++) {
        make_union(i);
    }

    for (int i = 1; i <= n; i++) {
        ll a, b;
        cin >> a >> b;
        point.emplace_back(a, b, i);
    }    

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            auto [a, b, p1] = point[i];
            auto [c, d, p2] = point[j];

            ll len = dis(a, b, c, d);
            edge.emplace_back(len, p1, p2);
        }
    }

    sort(edge.begin(), edge.end());

    ll cost = 0.0;
    int num = 0;
    for (auto [w, u, v] : edge) {
        if (merge_union(u, v)) {
            cost = max(cost, w);
            num++;
        }

        if (num == n - 1)
            break;
    }

    cout << fixed << setprecision(9) << cost/2.0;
}

Compilation message

odasiljaci.cpp: In function 'int main()':
odasiljaci.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("TASK.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
odasiljaci.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen("TASK.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Unexpected end of file - double expected
2 Incorrect 2 ms 340 KB Unexpected end of file - double expected
3 Incorrect 2 ms 340 KB Unexpected end of file - double expected
4 Incorrect 2 ms 340 KB Unexpected end of file - double expected
5 Incorrect 2 ms 340 KB Unexpected end of file - double expected
6 Incorrect 2 ms 340 KB Unexpected end of file - double expected
7 Incorrect 2 ms 340 KB Unexpected end of file - double expected
8 Incorrect 2 ms 340 KB Unexpected end of file - double expected
9 Incorrect 2 ms 340 KB Unexpected end of file - double expected
10 Incorrect 2 ms 340 KB Unexpected end of file - double expected