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 <bits/stdc++.h>
#include "swap.h"
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define F first
#define S second
#define PB push_back
#define FOR(i, n) for (int i = 0; i < n; i++)
const int maxn = 1e5 + 10;
const ll LLINF = 1ll<<50;
ll n, m, dist[maxn], p[maxn], rev_dist[maxn], rev_p[maxn];
vector<pii> adj[maxn];
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W){
n = N, m = M;
FOR(i, m){
adj[U[i]].PB({V[i], W[i]});
adj[V[i]].PB({U[i], W[i]});
}
}
int getMinimumFuelCapacity(int X, int Y){
fill(dist, dist + n, LLINF);
fill(rev_dist, rev_dist + n, LLINF);
fill(p, p + n, -1);
fill(rev_p, rev_p + n, -1);
priority_queue<pii> pq; pq.push({0, X});
dist[X] = 0;
while (!pq.empty()){
ll v = pq.top().S, d = -pq.top().F; pq.pop();
if (dist[v] < d) continue;
for (auto x : adj[v]){
ll u = x.F, w = x.S;
if (dist[u] <= max(d, w)) continue;
dist[u] = max(d, w), p[u] = v;
pq.push({-dist[u], u});
}
}
if (dist[Y] >= LLINF) return -1;
ll mn = LLINF;
pq = priority_queue<pii>();
pq.push({0, Y}); rev_dist[Y] = 0;
while (!pq.empty()){
ll v = pq.top().S, d = -pq.top().F; pq.pop();
if (rev_dist[v] < d) continue;
for (auto x : adj[v]){
ll u = x.F, w = x.S;
if (u != p[v] && u != rev_p[v] && v != X){
// cout << u << ' ' << v << ' ' << endl;
mn = min(mn, max({dist[u], d, w}));
}
if (rev_dist[u] <= max(d, w)) continue;
rev_dist[u] = max(d, w), rev_p[u] = v;
pq.push({-rev_dist[u], u});
}
}
// FOR(i, n) cout << dist[i] << ' '; cout << endl;
// FOR(i, n) cout << rev_dist[i] << ' '; cout << endl;
if (mn >= LLINF) return -1;
// cout << dist[Y] << ' ' << mn << endl;
return max(mn, dist[Y]);
}
# | 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... |