#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 (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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
6480 KB |
Output is correct |
10 |
Correct |
438 ms |
7704 KB |
Output is correct |
11 |
Correct |
636 ms |
7704 KB |
Output is correct |
12 |
Correct |
580 ms |
8016 KB |
Output is correct |
13 |
Correct |
853 ms |
8028 KB |
Output is correct |
14 |
Execution timed out |
2003 ms |
6480 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
2045 ms |
10352 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
512 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 |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
1 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 |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
572 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
160 ms |
6480 KB |
Output is correct |
11 |
Correct |
438 ms |
7704 KB |
Output is correct |
12 |
Correct |
636 ms |
7704 KB |
Output is correct |
13 |
Correct |
580 ms |
8016 KB |
Output is correct |
14 |
Correct |
853 ms |
8028 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 |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
572 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
12 ms |
1372 KB |
Output is correct |
35 |
Correct |
906 ms |
8028 KB |
Output is correct |
36 |
Correct |
745 ms |
8028 KB |
Output is correct |
37 |
Correct |
674 ms |
8020 KB |
Output is correct |
38 |
Correct |
735 ms |
8028 KB |
Output is correct |
39 |
Correct |
503 ms |
8028 KB |
Output is correct |
40 |
Correct |
618 ms |
7512 KB |
Output is correct |
41 |
Correct |
610 ms |
8284 KB |
Output is correct |
42 |
Correct |
1031 ms |
8020 KB |
Output is correct |
43 |
Correct |
706 ms |
8028 KB |
Output is correct |
44 |
Correct |
247 ms |
8684 KB |
Output is correct |
45 |
Correct |
315 ms |
10184 KB |
Output is correct |
46 |
Correct |
629 ms |
8016 KB |
Output is correct |
47 |
Correct |
444 ms |
8184 KB |
Output is correct |
48 |
Correct |
296 ms |
8656 KB |
Output is correct |
49 |
Correct |
73 ms |
8952 KB |
Output is correct |
50 |
Correct |
78 ms |
6728 KB |
Output is correct |
51 |
Correct |
221 ms |
8904 KB |
Output is correct |
52 |
Correct |
309 ms |
11804 KB |
Output is correct |
53 |
Correct |
203 ms |
12564 KB |
Output is correct |
54 |
Correct |
1049 ms |
13612 KB |
Output is correct |
55 |
Correct |
460 ms |
8024 KB |
Output is correct |
56 |
Correct |
408 ms |
12184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
160 ms |
6480 KB |
Output is correct |
10 |
Correct |
438 ms |
7704 KB |
Output is correct |
11 |
Correct |
636 ms |
7704 KB |
Output is correct |
12 |
Correct |
580 ms |
8016 KB |
Output is correct |
13 |
Correct |
853 ms |
8028 KB |
Output is correct |
14 |
Execution timed out |
2003 ms |
6480 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
160 ms |
6480 KB |
Output is correct |
11 |
Correct |
438 ms |
7704 KB |
Output is correct |
12 |
Correct |
636 ms |
7704 KB |
Output is correct |
13 |
Correct |
580 ms |
8016 KB |
Output is correct |
14 |
Correct |
853 ms |
8028 KB |
Output is correct |
15 |
Execution timed out |
2003 ms |
6480 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |