Submission #777848

# Submission time Handle Problem Language Result Execution time Memory
777848 2023-07-09T18:42:28 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, 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) {
    return max(pmax[Y], min(mn, ad[Y]));
}
# 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 -