Submission #777857

# Submission time Handle Problem Language Result Execution time Memory
777857 2023-07-09T19:16:52 Z t6twotwo Swapping Cities (APIO20_swap) C++17
0 / 100
1 ms 212 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int N;
vector<tuple<int, int, int>> edges;
constexpr int inf = 2e9;
void init(int n, int M, vector<int> U, vector<int> V, vector<int> W) {
    N = n;
    for (int i = 0; i < M; i++) {
        edges.emplace_back(W[i], U[i], V[i]);
    }
    sort(edges.begin(), edges.end());
}
int getMinimumFuelCapacity(int X, int Y) {
    vector<int> p(N);
    function<int(int)> find = [&](int x) {
        return x == p[x] ? x : p[x] = find(p[x]);
    };
    vector<int> sz(N, 1), cnt(N);
    auto unite = [&](int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            cnt[x]++;
            return;
        }
        if (sz[x] > sz[y]) {
            swap(x, y);
        }
        p[x] = y;
        sz[y] += sz[x];
        cnt[y] += cnt[x] + 1;
    };
    for (auto [z, x, y] : edges) {
        unite(x, y);
        if (find(X) == find(Y)) {
            if (cnt[find(X)] >= sz[find(X)]) {
                return z;
            }
        }
    }
    return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -