Submission #674623

# Submission time Handle Problem Language Result Execution time Memory
674623 2022-12-25T12:43:28 Z Vahe Swapping Cities (APIO20_swap) C++17
7 / 100
2000 ms 8392 KB
#include "swap.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
vector<vector<pair<int, int>>> gp;
int n, m;
vector<int> u, v, w, ver, var, par, P, p, her, sizes;

int get(int u)
{
    if (u == par[u]) return u;
    return par[u] = get(par[u]);
}

void union_chains(int u, int v, int w)
{
    if (get(u) == get(v))
    {
        P[get(u)] = min(P[get(u)], w);
        return;
    }
    int a = get(u), b = get(v);
    if (sizes[a] < sizes[b]) swap(a, b), swap(u, v);
    sizes[a] += sizes[b];
    par[b] = par[a];
    her[v] = w, p[v] = u;
    if      (u == ver[a] && v == ver[b]) ver[a] = var[b];
    else if (u == ver[a] && v == var[b]) ver[a] = ver[b];
    else if (u == var[a] && v == ver[b]) var[a] = var[b];
    else if (u == var[a] && v == var[b]) var[a] = ver[b];
    else ver[a] = -1, var[a] = -1, P[u] = min(P[u], w);
}

int go(int u, int w)
{
    if (p[u] == u || her[u] > w) return u;
    return go(p[u], w);
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N, m = M;
    vector<pair<int, pair<int, int>>> kox;
    for (int i = 0; i < m; i++) kox.push_back({ W[i], {U[i], V[i]} });
    sort(kox.begin(), kox.end());
    ver = var = par = sizes = P = her = p = vector<int>(n);
    for (int i = 0; i < n; i++) ver[i] = var[i] = par[i] = p[i] = i, sizes[i] = 1, her[i] = P[i] = INT_MAX;
    for (int i = 0; i < m; i++)
    {
        int u = kox[i].second.first, v = kox[i].second.second;
        union_chains(u, v, kox[i].first);
    }

}

int getMinimumFuelCapacity(int X, int Y) {
    long long l = -1, r = 2e9;
    while (l + 1 < r)
    {
        int mij = l + (r - l) / 2;
        int a = go(X, mij), b = go(Y, mij);
        if (a == b && P[get(a)] <= mij) r = mij;
        else l = mij;
    }
    return r != 2e9 ? r : -1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 35 ms 5180 KB Output is correct
10 Correct 42 ms 6208 KB Output is correct
11 Correct 41 ms 6148 KB Output is correct
12 Correct 44 ms 6460 KB Output is correct
13 Correct 96 ms 6464 KB Output is correct
14 Correct 43 ms 5316 KB Output is correct
15 Correct 138 ms 7832 KB Output is correct
16 Correct 136 ms 7664 KB Output is correct
17 Correct 138 ms 8120 KB Output is correct
18 Execution timed out 2063 ms 8112 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 140 ms 8136 KB Output is correct
4 Correct 150 ms 8136 KB Output is correct
5 Correct 148 ms 8392 KB Output is correct
6 Correct 161 ms 8080 KB Output is correct
7 Correct 164 ms 8252 KB Output is correct
8 Correct 140 ms 8156 KB Output is correct
9 Correct 143 ms 8160 KB Output is correct
10 Correct 142 ms 8048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 35 ms 5180 KB Output is correct
11 Correct 42 ms 6208 KB Output is correct
12 Correct 41 ms 6148 KB Output is correct
13 Correct 44 ms 6460 KB Output is correct
14 Correct 96 ms 6464 KB Output is correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 35 ms 5180 KB Output is correct
10 Correct 42 ms 6208 KB Output is correct
11 Correct 41 ms 6148 KB Output is correct
12 Correct 44 ms 6460 KB Output is correct
13 Correct 96 ms 6464 KB Output is correct
14 Correct 43 ms 5316 KB Output is correct
15 Correct 138 ms 7832 KB Output is correct
16 Correct 136 ms 7664 KB Output is correct
17 Correct 138 ms 8120 KB Output is correct
18 Execution timed out 2063 ms 8112 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 35 ms 5180 KB Output is correct
11 Correct 42 ms 6208 KB Output is correct
12 Correct 41 ms 6148 KB Output is correct
13 Correct 44 ms 6460 KB Output is correct
14 Correct 96 ms 6464 KB Output is correct
15 Correct 43 ms 5316 KB Output is correct
16 Correct 138 ms 7832 KB Output is correct
17 Correct 136 ms 7664 KB Output is correct
18 Correct 138 ms 8120 KB Output is correct
19 Execution timed out 2063 ms 8112 KB Time limit exceeded
20 Halted 0 ms 0 KB -