Submission #742200

# Submission time Handle Problem Language Result Execution time Memory
742200 2023-05-15T18:45:50 Z 1zaid1 Swapping Cities (APIO20_swap) C++17
0 / 100
4 ms 5176 KB
#include <bits/stdc++.h>
using namespace std;

const int M = 1e5+5;
vector<array<int, 3>> E;
vector<int> node[M];

int n, m;
void init(int _n, int _m, vector<int> U, vector<int> V, vector<int> W) {
    n = _n, m = _m;
    for (int i = 0; i < m; i++) E.push_back({U[i], V[i], W[i]});
    sort(E.begin(), E.end(), [](array<int, 3> a, array<int, 3> b){return a[2] < b[2];});
}

int mn[M], vis[M], p[M], d[M];
void clear() {
    for (int i = 0; i < n; i++) {
        vis[i] = mn[i] = p[i] = d[i] = 0;
        node[i].clear();
    }
}

void dfs(int s, int P) {
    vis[s] = true;
    d[s] = d[P]+1;
    p[s] = P;

    vector<int> c;
    mn[s] = INT_MAX;
    for (int i:node[s]) {
        if (!vis[i]) dfs(i, s), c.push_back(i);
        else if (i != P) mn[s] = min(mn[s], d[i]);
    }

    for (int i:c) mn[s] = min(mn[s], mn[i]);
}

bool check(int a, int b, int X) {
    clear();

    for (int i = 0; i < X; i++) {
        auto [A, B, C] = E[i];
        node[A].push_back(B);
        node[B].push_back(A);
    }

    dfs(a, a);
    int mxD = 0;
    int x = p[b];
    if (!vis[b]) return 0;

    while (x != a) mxD = max(mxD, (int)node[x].size()), x = p[x];
    return mxD > 2 || mn[b] == 1;
} 

int solve(int a, int b) {
    int x = 0, p2 = (1<<18);
    while (p2 /= 2) {
        if (!check(a, b, x+p2)) x += p2;
    }

    if (x==m) return -1;
    return E[x][2];
}

int getMinimumFuelCapacity(int X, int Y) {
    return solve(X, Y);
}
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -