This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define db double
#define ll long long
#define ar array
template<typename T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
vector<vector<ar<int, 3>>> adj;
int n, m;
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N, m = M;
adj.resize(N + 1);
for (int i = 0; i < M; i++) {
adj[U[i]].push_back({V[i], W[i], i});
adj[V[i]].push_back({U[i], W[i], i});
}
}
int getMinimumFuelCapacity(int X, int Y) {
auto good = [&](int mid) {
vector<int> dist(n+1, 1e9), p(n+1), who(n+1);
queue<int> q;
q.push(X), dist[X] = 0;
while (q.size()) {
int v = q.front(); q.pop();
for (auto [u, w, idx] : adj[v]) if (w <= mid && ckmin(dist[u], dist[v] + 1)) {
q.push(u);
p[u] = v, who[u] = idx;
}
}
if (dist[Y] == int(1e9)) return 0;
vector<bool> bad(m);
for (int s = Y, from = -1; s != X; from = s, s = p[s]) {
bad[who[s]] = 1;
if (s != Y) {
for (auto x : adj[s]) {
if (x[1] <= mid && x[0] != p[s] && x[0] != from) {
return 1;
}
}
}
}
vector<bool> vis2(n+1);
vis2[X] = 1;
q.push(X);
while (q.size()) {
int v = q.front(); q.pop();
if (v == Y) return 1;
for (auto [u, w, idx] : adj[v]) if (w <= mid && !bad[idx] && !vis2[u]) {
vis2[u] = 1, q.push(u);
}
}
return 0;
};
int l = 1, r = 1e9, ans = 1e9;
if (!good(r)) return -1;
while (l <= r) {
int mid = (l+r)/2;
if (good(mid)) ans = mid, r = mid-1;
else l = mid+1;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |