#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
508 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
35 ms |
6492 KB |
Output is correct |
10 |
Correct |
62 ms |
7864 KB |
Output is correct |
11 |
Correct |
62 ms |
7764 KB |
Output is correct |
12 |
Correct |
77 ms |
8188 KB |
Output is correct |
13 |
Correct |
81 ms |
8276 KB |
Output is correct |
14 |
Execution timed out |
2064 ms |
6592 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2100 ms |
11436 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
508 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
35 ms |
6492 KB |
Output is correct |
11 |
Correct |
62 ms |
7864 KB |
Output is correct |
12 |
Correct |
62 ms |
7764 KB |
Output is correct |
13 |
Correct |
77 ms |
8188 KB |
Output is correct |
14 |
Correct |
81 ms |
8276 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
508 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
35 ms |
6492 KB |
Output is correct |
10 |
Correct |
62 ms |
7864 KB |
Output is correct |
11 |
Correct |
62 ms |
7764 KB |
Output is correct |
12 |
Correct |
77 ms |
8188 KB |
Output is correct |
13 |
Correct |
81 ms |
8276 KB |
Output is correct |
14 |
Execution timed out |
2064 ms |
6592 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
35 ms |
6492 KB |
Output is correct |
11 |
Correct |
62 ms |
7864 KB |
Output is correct |
12 |
Correct |
62 ms |
7764 KB |
Output is correct |
13 |
Correct |
77 ms |
8188 KB |
Output is correct |
14 |
Correct |
81 ms |
8276 KB |
Output is correct |
15 |
Execution timed out |
2064 ms |
6592 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |