Submission #558630

# Submission time Handle Problem Language Result Execution time Memory
558630 2022-05-07T17:18:12 Z proma Swapping Cities (APIO20_swap) C++17
0 / 100
2000 ms 17284 KB
#include "swap.h"
#include <bits/stdc++.h>

#define see(x) cout<<#x<<"="<<x<<"\n";

using namespace std;

const int N = 1e5+5;

int n, m, used[N], par[N], flag, cycleS, cycleF;
vector <pair <int, int>> g[N];
vector <int> val;

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 ++) {
        g[U[i]].push_back({V[i], W[i]});
        g[V[i]].push_back({U[i], W[i]});
        val.push_back(W[i]);
    }
    sort(val.begin(), val.end());
}

void dfs(int v, int p, int k, int x, int y) {
    used[v] = 1;
    par[v] = p;
    if (v != x and v != y and g[v].size() > 2) flag = 1;
    for (auto i: g[v]) {
        if (i.second > k or i.first == p) continue;
        if (used[i.first]) {
            cycleS = i.first;
            cycleF = v;
        }
        else dfs(i.first, v, k, x, y);
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    int l = 0, r = m - 1, best = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        flag = 0;
        cycleS = cycleF = -1;
        memset(used, 0, sizeof(used));
        par[X] = -1;
        dfs(X, 0, val[mid], X, Y);
        if (cycleS != -1) {
            int cnt = 0;
            for (int i = cycleS; i != par[cycleF]; i = par[i]) {
                if (i == X or i == Y) cnt ++;
            }
            if (cnt > 1) flag = 1;
        }
        if (used[Y] and flag) {
            best = val[mid];
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    return best;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 3 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 3 ms 3156 KB Output is correct
8 Correct 3 ms 3196 KB Output is correct
9 Correct 77 ms 14764 KB Output is correct
10 Correct 153 ms 16432 KB Output is correct
11 Correct 176 ms 16776 KB Output is correct
12 Correct 225 ms 16556 KB Output is correct
13 Correct 492 ms 17284 KB Output is correct
14 Execution timed out 2068 ms 15148 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Execution timed out 2025 ms 12772 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 3 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 3 ms 3156 KB Output is correct
8 Correct 3 ms 3196 KB Output is correct
9 Correct 2 ms 3048 KB Output is correct
10 Correct 3 ms 3068 KB Output is correct
11 Correct 3 ms 3156 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 3 ms 3048 KB Output is correct
14 Correct 3 ms 3028 KB Output is correct
15 Incorrect 3 ms 3028 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3048 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 3 ms 3156 KB Output is correct
8 Correct 3 ms 3156 KB Output is correct
9 Correct 3 ms 3196 KB Output is correct
10 Correct 77 ms 14764 KB Output is correct
11 Correct 153 ms 16432 KB Output is correct
12 Correct 176 ms 16776 KB Output is correct
13 Correct 225 ms 16556 KB Output is correct
14 Correct 492 ms 17284 KB Output is correct
15 Correct 3 ms 3068 KB Output is correct
16 Correct 3 ms 3156 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 3 ms 3048 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Incorrect 3 ms 3028 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 3 ms 3156 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 3 ms 3156 KB Output is correct
8 Correct 3 ms 3196 KB Output is correct
9 Correct 77 ms 14764 KB Output is correct
10 Correct 153 ms 16432 KB Output is correct
11 Correct 176 ms 16776 KB Output is correct
12 Correct 225 ms 16556 KB Output is correct
13 Correct 492 ms 17284 KB Output is correct
14 Execution timed out 2068 ms 15148 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3048 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 3 ms 3156 KB Output is correct
8 Correct 3 ms 3156 KB Output is correct
9 Correct 3 ms 3196 KB Output is correct
10 Correct 77 ms 14764 KB Output is correct
11 Correct 153 ms 16432 KB Output is correct
12 Correct 176 ms 16776 KB Output is correct
13 Correct 225 ms 16556 KB Output is correct
14 Correct 492 ms 17284 KB Output is correct
15 Execution timed out 2068 ms 15148 KB Time limit exceeded
16 Halted 0 ms 0 KB -