#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
vector <vector <pair <int, int>>> adj;
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]});
}
}
const int maxn = 1e5 + 1;
int dis[maxn];
priority_queue <pair <int, int>> pq;
bool vis[maxn], processed[maxn];
bool skip = true;
int dfs(int s, int p, int st) {
if (s == st && !skip) {
return 0;
}
skip = false;
if (vis[s])
return 1e9;
vis[s] = true;
int ans = 1e9;
for (auto i : adj[s]) {
if (i.first == p)
continue;
ans = min(ans, max(i.second, dfs(i.first, s, st)));
}
vis[s] = false;
return ans;
}
int getMinimumFuelCapacity(int x, int y) {
fill(processed, processed + n + 1, false);
pq.push({0, x});
fill(dis, dis + n + 1, 1e9 + 1);
dis[x] = 0;
while (!pq.empty()) {
int s = pq.top().second;
pq.pop();
if (processed[s])
continue;
processed[s] = true;
for (auto i : adj[s]) {
int d = max(dis[s], i.second);
if (d < dis[i.first]) {
dis[i.first] = d;
pq.push({-d, i.first});
}
}
}
if (dis[y] == 1e9 + 1)
return -1;
skip = true;
fill(vis, vis + n + 1, false);
int ans = dfs(x, x, x);
return max(ans, dis[y]);
}
// 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';
// }
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |