Submission #777878

# Submission time Handle Problem Language Result Execution time Memory
777878 2023-07-09T20:38: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, M;
vector<int> f, up, p;
int find(int x) {
    return x == p[x] ? x : p[x] = find(p[x]);
}
constexpr int inf = 2e9;
void init(int n, int m, vector<int> U, vector<int> V, vector<int> W) {
    N = n;
    M = m;
    p.resize(N);
    iota(p.begin(), p.end(), 0);
    vector<tuple<int, int, int>> edges(M);
    for (int i = 0; i < M; i++) {
        edges[i] = {W[i], U[i], V[i]};
    }
    sort(edges.begin(), edges.end());
    up.resize(N, -1);
    f.resize(N, inf);
    int K = N;
    vector<int> deg(N);
    for (auto [z, a, b] : edges) {
        int x = find(a);
        int y = find(b);
        if (x == y) {
            f[x] = min(f[x], z);
            continue;
        }
        f.push_back(min(inf, max(min(f[x], f[y]), z)));
        if (++deg[a] == 3 || ++deg[b] == 3) {
            f[K] = min(f[K], z);
        }
        p.push_back(K);
        up.push_back(-1);
        p[x] = p[y] = up[x] = up[y] = K++;
    }
}
int getMinimumFuelCapacity(int x, int y) {
    if (find(x) != find(y)) {
        return -1;
    }
    while (x != y) {
        if (x < y) {
            x = up[x];
        } else {
            y = up[y];
        }
    }
    int ans = inf;
    while (x != -1) {
        ans = min(ans, f[x]);
        x = up[x];
    }
    return ans;
}
# 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 -