#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<pii> q;
vector<bool> visX(n);
vector<int> p(n, -1);
q.push({X, -1}); visX[X] = true;
while (!q.empty()) {
auto [x, pr] = q.front(); q.pop();
for (auto [i, w] : E[x]) {
if (i == pr || w > md) continue;
if (visX[i]) {
if (i == X) {
tr = true;
break;
}
}
else {
p[i] = x;
q.push({i, x});
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 (w > md || i == p) continue;
if (visY[i]) {
if (i == Y || 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]) {
cnt += (w <= md);
}
tr = (cnt > 2);
}
if (!tr) l = md + 1;
else r = md;
}
return (l == (int)1e9 + 1 ? -1 : l);
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
516 KB |
Output is correct |
7 |
Correct |
3 ms |
444 KB |
Output is correct |
8 |
Correct |
5 ms |
348 KB |
Output is correct |
9 |
Correct |
185 ms |
8012 KB |
Output is correct |
10 |
Correct |
461 ms |
9752 KB |
Output is correct |
11 |
Correct |
667 ms |
9808 KB |
Output is correct |
12 |
Correct |
600 ms |
10320 KB |
Output is correct |
13 |
Correct |
937 ms |
10332 KB |
Output is correct |
14 |
Execution timed out |
2051 ms |
8536 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 |
Execution timed out |
2100 ms |
14732 KB |
Time limit exceeded |
4 |
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 |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
516 KB |
Output is correct |
7 |
Correct |
3 ms |
444 KB |
Output is correct |
8 |
Correct |
5 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
444 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 |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
18 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
5 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
516 KB |
Output is correct |
8 |
Correct |
3 ms |
444 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
185 ms |
8012 KB |
Output is correct |
11 |
Correct |
461 ms |
9752 KB |
Output is correct |
12 |
Correct |
667 ms |
9808 KB |
Output is correct |
13 |
Correct |
600 ms |
10320 KB |
Output is correct |
14 |
Correct |
937 ms |
10332 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
444 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 |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
5 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
600 KB |
Output is correct |
34 |
Correct |
15 ms |
1792 KB |
Output is correct |
35 |
Correct |
962 ms |
9964 KB |
Output is correct |
36 |
Correct |
799 ms |
10076 KB |
Output is correct |
37 |
Correct |
720 ms |
10064 KB |
Output is correct |
38 |
Correct |
734 ms |
9820 KB |
Output is correct |
39 |
Correct |
581 ms |
9804 KB |
Output is correct |
40 |
Correct |
648 ms |
9296 KB |
Output is correct |
41 |
Correct |
671 ms |
10332 KB |
Output is correct |
42 |
Correct |
1041 ms |
10012 KB |
Output is correct |
43 |
Correct |
745 ms |
10068 KB |
Output is correct |
44 |
Correct |
256 ms |
10836 KB |
Output is correct |
45 |
Correct |
340 ms |
13392 KB |
Output is correct |
46 |
Correct |
724 ms |
10068 KB |
Output is correct |
47 |
Correct |
591 ms |
10068 KB |
Output is correct |
48 |
Correct |
371 ms |
10840 KB |
Output is correct |
49 |
Correct |
67 ms |
11600 KB |
Output is correct |
50 |
Correct |
69 ms |
9044 KB |
Output is correct |
51 |
Correct |
219 ms |
11600 KB |
Output is correct |
52 |
Correct |
348 ms |
15188 KB |
Output is correct |
53 |
Correct |
222 ms |
16208 KB |
Output is correct |
54 |
Correct |
1066 ms |
17488 KB |
Output is correct |
55 |
Correct |
528 ms |
10076 KB |
Output is correct |
56 |
Correct |
491 ms |
15884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
516 KB |
Output is correct |
7 |
Correct |
3 ms |
444 KB |
Output is correct |
8 |
Correct |
5 ms |
348 KB |
Output is correct |
9 |
Correct |
185 ms |
8012 KB |
Output is correct |
10 |
Correct |
461 ms |
9752 KB |
Output is correct |
11 |
Correct |
667 ms |
9808 KB |
Output is correct |
12 |
Correct |
600 ms |
10320 KB |
Output is correct |
13 |
Correct |
937 ms |
10332 KB |
Output is correct |
14 |
Execution timed out |
2051 ms |
8536 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
516 KB |
Output is correct |
8 |
Correct |
3 ms |
444 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
185 ms |
8012 KB |
Output is correct |
11 |
Correct |
461 ms |
9752 KB |
Output is correct |
12 |
Correct |
667 ms |
9808 KB |
Output is correct |
13 |
Correct |
600 ms |
10320 KB |
Output is correct |
14 |
Correct |
937 ms |
10332 KB |
Output is correct |
15 |
Execution timed out |
2051 ms |
8536 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |