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;
vector <vector <pair <int, int>>> adj;
vector <array <int, 3>> edges;
int n, m;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
adj.resize(N+1);
n = N;
m = M;
for (int i = 0; i < M; i++) {
adj[U[i]].push_back({V[i], W[i]});
adj[V[i]].push_back({U[i], W[i]});
edges.push_back({U[i], V[i], W[i]});
edges.push_back({V[i], U[i], W[i]});
}
}
int getMinimumFuelCapacity(int x, int y) {
vector <vector <int>> dis(n, vector <int> (n, 1e9 + 1));
dis[x][y] = 0;
queue <array <int, 3>> pq;
pq.push({0, x, y});
vector <vector <bool>> processed(n, vector <bool> (n));
while (!pq.empty()) {
int a = pq.front()[1], b = pq.front()[2];
pq.pop();
if (processed[a][b])
continue;
processed[a][b] = true;
for (auto i : adj[a]) {
for (auto j : adj[b]) {
int d = max({dis[a][b], i.second, j.second});
if (d < dis[i.first][j.first] && i.first != j.first && (i.first != b || j.first != a)) {
dis[i.first][j.first] = d;
pq.push({-d, i.first, j.first});
}
d = max(dis[a][b], i.second);
if (d < dis[i.first][b] && i.first != b) {
dis[i.first][b] = d;
pq.push({-d, i.first, b});
}
d = max(dis[a][b], j.second);
if (d < dis[a][j.first] && a != j.first) {
dis[a][j.first] = d;
pq.push({-d, a, j.first});
}
}
}
}
if (dis[y][x] == 1e9 + 1)
dis[y][x] = -1;
return dis[y][x];
}
// int main() {
// int N, M;
// cin >> N >> M;
// vector <int> u(M), v(M), w(M);
// for (int i = 0; i < M; i++)
// cin >> u[i] >> v[i] >> w[i];
// init(N, M, u, v, w);
// int q;
// cin >> q;
// while (q--) {
// int x, y;
// cin >> x >> y;
// cout << getMinimumFuelCapacity(x, y) << '\n';
// }
// }
# | 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... |