#include <bits/stdc++.h>
#include "swap.h"
using namespace std;
using ll = long long;
#define ff first
#define ss second
#define pii pair<int, int>
int n;
vector<vector<pii>> E;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N;
E.assign(n, {});
for (int i = 0; i < M; i++) {
E[U[i]].push_back({V[i], W[i]});
E[V[i]].push_back({U[i], W[i]});
}
}
int getMinimumFuelCapacity(int X, int Y) {
int l = 0, r = (int)1e9 + 1;
while (l < r) {
int md = (l + r) >> 1;
bool tr = false;
queue<int> q;
vector<bool> visX(n);
q.push(X); visX[X] = true;
while (!q.empty()) {
int x = q.front(); q.pop();
for (auto [i, w] : E[x]) {
if (w <= md && !visX[i]) {
q.push(i);
visX[i] = true;
}
}
}
if (!visX[Y]) {
l = md + 1;
continue;
}
vector<bool> visY(n);
queue<pii> q1;
q1.push({Y, -1}); visY[Y] = true;
while (!q1.empty() && !tr) {
auto [x, p] = q1.front(); q1.pop();
for (auto [i, w] : E[x]) {
if (i == p || w > md) continue;
if (visY[i]) {
if (visX[i]) {
tr = true;
break;
}
}
else {
visY[i] = true;
q1.push({i, x});
}
}
}
for (int i = 0; i < n && !tr; i++) {
if (!visX[i] || !visY[i]) continue;
int cnt = 0;
for (auto [j, w] : E[i]) {
if ((cnt += (w <= md)) > 2) break;
}
tr = (cnt > 2);
}
if (!tr) l = md + 1;
else r = md;
}
return (l == (int)1e9 + 1 ? -1 : l);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
158 ms |
6596 KB |
Output is correct |
10 |
Correct |
436 ms |
7772 KB |
Output is correct |
11 |
Correct |
610 ms |
7768 KB |
Output is correct |
12 |
Correct |
586 ms |
8028 KB |
Output is correct |
13 |
Correct |
812 ms |
8020 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
6492 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2036 ms |
10432 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 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 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
452 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
158 ms |
6596 KB |
Output is correct |
11 |
Correct |
436 ms |
7772 KB |
Output is correct |
12 |
Correct |
610 ms |
7768 KB |
Output is correct |
13 |
Correct |
586 ms |
8028 KB |
Output is correct |
14 |
Correct |
812 ms |
8020 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 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 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
15 ms |
1372 KB |
Output is correct |
35 |
Correct |
938 ms |
8020 KB |
Output is correct |
36 |
Correct |
711 ms |
8072 KB |
Output is correct |
37 |
Correct |
641 ms |
8024 KB |
Output is correct |
38 |
Correct |
635 ms |
8092 KB |
Output is correct |
39 |
Correct |
497 ms |
7912 KB |
Output is correct |
40 |
Correct |
559 ms |
7512 KB |
Output is correct |
41 |
Correct |
670 ms |
8028 KB |
Output is correct |
42 |
Correct |
1018 ms |
8020 KB |
Output is correct |
43 |
Correct |
711 ms |
8024 KB |
Output is correct |
44 |
Correct |
259 ms |
8528 KB |
Output is correct |
45 |
Correct |
294 ms |
10332 KB |
Output is correct |
46 |
Correct |
672 ms |
8020 KB |
Output is correct |
47 |
Correct |
520 ms |
8028 KB |
Output is correct |
48 |
Correct |
238 ms |
8784 KB |
Output is correct |
49 |
Correct |
64 ms |
8960 KB |
Output is correct |
50 |
Correct |
71 ms |
6744 KB |
Output is correct |
51 |
Correct |
190 ms |
8956 KB |
Output is correct |
52 |
Correct |
300 ms |
11600 KB |
Output is correct |
53 |
Correct |
181 ms |
12520 KB |
Output is correct |
54 |
Correct |
973 ms |
13548 KB |
Output is correct |
55 |
Correct |
436 ms |
8280 KB |
Output is correct |
56 |
Correct |
403 ms |
12112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
158 ms |
6596 KB |
Output is correct |
10 |
Correct |
436 ms |
7772 KB |
Output is correct |
11 |
Correct |
610 ms |
7768 KB |
Output is correct |
12 |
Correct |
586 ms |
8028 KB |
Output is correct |
13 |
Correct |
812 ms |
8020 KB |
Output is correct |
14 |
Execution timed out |
2074 ms |
6492 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
158 ms |
6596 KB |
Output is correct |
11 |
Correct |
436 ms |
7772 KB |
Output is correct |
12 |
Correct |
610 ms |
7768 KB |
Output is correct |
13 |
Correct |
586 ms |
8028 KB |
Output is correct |
14 |
Correct |
812 ms |
8020 KB |
Output is correct |
15 |
Execution timed out |
2074 ms |
6492 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |