Submission #777849

# Submission time Handle Problem Language Result Execution time Memory
777849 2023-07-09T18:43:21 Z t6twotwo Swapping Cities (APIO20_swap) C++17
0 / 100
335 ms 524288 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int N, mn;
vector<int> pmax, ad;
constexpr int inf = 2e9;
void init(int n, int M, vector<int> U, vector<int> V, vector<int> W) {
    N = n;
    mn = inf;
    ad.resize(N, inf);
    pmax.resize(N);
    vector<vector<pair<int, int>>> adj(N);
    for (int i = 0; i < M; i++) {
        adj[U[i]].emplace_back(W[i], V[i]);
        adj[V[i]].emplace_back(W[i], U[i]);
    }
    for (auto &v : adj) {
        sort(v.begin(), v.end());
    }
    vector<int> stk{inf};
    auto dfs = [&](auto dfs, int x) -> void {
        ad[x] = stk.back();
        for (auto [z, y] : adj[x]) {
            adj[y].erase(find(adj[y].begin(), adj[y].end(), pair{z, x}));
            pmax[y] = max(pmax[x], z);
            if (x != 0 && adj[x].size() > 1) {
                stk.push_back(min(stk.back(), adj[x][0] == pair{z, y} ? adj[x][1].first : adj[x][0].first));
            }
            dfs(dfs, y);
            if (x != 0 && adj[x].size() > 1) {
                stk.pop_back();
            }
        }
        if (x != 0 && adj[x].size() > 1) {
            mn = min(mn, adj[x][1].first);
        }
    };
    dfs(dfs, 0);
}
int getMinimumFuelCapacity(int X, int Y) {
    int ans = max(pmax[Y], min(mn, ad[Y]));
    if (ans == inf) {
        ans = -1;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 440 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 444 KB Output is correct
9 Correct 35 ms 13652 KB Output is correct
10 Correct 45 ms 18184 KB Output is correct
11 Correct 43 ms 17264 KB Output is correct
12 Correct 46 ms 18608 KB Output is correct
13 Correct 58 ms 21132 KB Output is correct
14 Correct 41 ms 12856 KB Output is correct
15 Correct 87 ms 19512 KB Output is correct
16 Correct 83 ms 16864 KB Output is correct
17 Correct 113 ms 22644 KB Output is correct
18 Correct 90 ms 20628 KB Output is correct
19 Incorrect 40 ms 6708 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 79 ms 12128 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 440 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 444 KB Output is correct
9 Runtime error 335 ms 524288 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 335 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 440 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 444 KB Output is correct
9 Correct 35 ms 13652 KB Output is correct
10 Correct 45 ms 18184 KB Output is correct
11 Correct 43 ms 17264 KB Output is correct
12 Correct 46 ms 18608 KB Output is correct
13 Correct 58 ms 21132 KB Output is correct
14 Correct 41 ms 12856 KB Output is correct
15 Correct 87 ms 19512 KB Output is correct
16 Correct 83 ms 16864 KB Output is correct
17 Correct 113 ms 22644 KB Output is correct
18 Correct 90 ms 20628 KB Output is correct
19 Incorrect 79 ms 12128 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 335 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -