#include "swap.h"
#include <bits/stdc++.h>
constexpr int N = 1e5;
std::vector<int> e[N];
std::vector<int> U, V, W, v;
int n, m;
void init(int n, int m, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
::U = U;
::V = V;
::W = W;
::n = n;
::m = m;
v = W;
sort(v.begin(), v.end());
}
std::vector<int> p;
std::vector<bool> vis;
bool have;
void dfs(int u, int P) {
p[u] = P;
vis[u] = true;
if (e[u].size() > 2) have = true;
for (auto v : e[u]) {
if (!vis[v]) {
dfs(v, u);
}
}
}
bool check(int X, int Y, int mid) {
for (int i = 0; i < n; i++) e[i].clear();
for (int i = 0; i < m; i++) {
if (W[i] <= mid) {
e[U[i]].emplace_back(V[i]);
e[V[i]].emplace_back(U[i]);
}
}
p.assign(n, -1);
vis.assign(n, false);
have = false;
dfs(X, -1);
if (p[Y] == -1)
return false;
if (have) {
return true;
}
int y = Y;
std::vector<int> got;
y = p[y];
while (y != -1 && p[y] != -1) {
got.push_back(y);
y = p[y];
}
std::vector<bool> bad(n, false);
for (auto x : got) {
bad[x] = true;
}
for (int i = 0; i < n; i++) e[i].clear();
for (int i = 0; i < m; i++) {
if (W[i] <= mid && !bad[U[i]] && !bad[V[i]]) {
e[U[i]].emplace_back(V[i]);
e[V[i]].emplace_back(U[i]);
}
}
if (!got.size()) {
e[X].erase(find(e[X].begin(), e[X].end(), Y));
e[Y].erase(find(e[Y].begin(), e[Y].end(), X));
}
p.assign(n, -1);
vis.assign(n, false);
dfs(X, -1);
if (p[Y] != -1)
return true;
return false;
}
int getMinimumFuelCapacity(int X, int Y) {
int l = -1, r = v.size();
while (l + 1 < r) {
int mid = (l + r) / 2;
if (check(X, Y, v[mid])) {
r = mid;
} else {
l = mid;
}
}
if (r == v.size()) return -1;
return v[r];
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:85:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | if (r == v.size()) return -1;
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
5 ms |
2636 KB |
Output is correct |
6 |
Correct |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
4 ms |
2764 KB |
Output is correct |
8 |
Correct |
6 ms |
2764 KB |
Output is correct |
9 |
Correct |
235 ms |
11908 KB |
Output is correct |
10 |
Correct |
631 ms |
13408 KB |
Output is correct |
11 |
Correct |
677 ms |
13928 KB |
Output is correct |
12 |
Correct |
774 ms |
14172 KB |
Output is correct |
13 |
Correct |
1212 ms |
14752 KB |
Output is correct |
14 |
Execution timed out |
2075 ms |
12272 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Execution timed out |
2071 ms |
11472 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
5 ms |
2636 KB |
Output is correct |
6 |
Correct |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
4 ms |
2764 KB |
Output is correct |
8 |
Correct |
6 ms |
2764 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
4 ms |
2636 KB |
Output is correct |
11 |
Correct |
4 ms |
2636 KB |
Output is correct |
12 |
Correct |
4 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2656 KB |
Output is correct |
14 |
Correct |
4 ms |
2636 KB |
Output is correct |
15 |
Correct |
4 ms |
2636 KB |
Output is correct |
16 |
Correct |
4 ms |
2636 KB |
Output is correct |
17 |
Correct |
4 ms |
2636 KB |
Output is correct |
18 |
Correct |
4 ms |
2636 KB |
Output is correct |
19 |
Correct |
4 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
4 ms |
2636 KB |
Output is correct |
22 |
Correct |
4 ms |
2636 KB |
Output is correct |
23 |
Correct |
4 ms |
2636 KB |
Output is correct |
24 |
Correct |
6 ms |
2784 KB |
Output is correct |
25 |
Correct |
6 ms |
2764 KB |
Output is correct |
26 |
Correct |
5 ms |
2764 KB |
Output is correct |
27 |
Correct |
4 ms |
2636 KB |
Output is correct |
28 |
Correct |
5 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
5 ms |
2636 KB |
Output is correct |
7 |
Correct |
4 ms |
2636 KB |
Output is correct |
8 |
Correct |
4 ms |
2764 KB |
Output is correct |
9 |
Correct |
6 ms |
2764 KB |
Output is correct |
10 |
Correct |
235 ms |
11908 KB |
Output is correct |
11 |
Correct |
631 ms |
13408 KB |
Output is correct |
12 |
Correct |
677 ms |
13928 KB |
Output is correct |
13 |
Correct |
774 ms |
14172 KB |
Output is correct |
14 |
Correct |
1212 ms |
14752 KB |
Output is correct |
15 |
Correct |
4 ms |
2636 KB |
Output is correct |
16 |
Correct |
4 ms |
2636 KB |
Output is correct |
17 |
Correct |
4 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2656 KB |
Output is correct |
19 |
Correct |
4 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
4 ms |
2636 KB |
Output is correct |
22 |
Correct |
4 ms |
2636 KB |
Output is correct |
23 |
Correct |
4 ms |
2636 KB |
Output is correct |
24 |
Correct |
4 ms |
2636 KB |
Output is correct |
25 |
Correct |
4 ms |
2636 KB |
Output is correct |
26 |
Correct |
4 ms |
2636 KB |
Output is correct |
27 |
Correct |
4 ms |
2636 KB |
Output is correct |
28 |
Correct |
4 ms |
2636 KB |
Output is correct |
29 |
Correct |
6 ms |
2784 KB |
Output is correct |
30 |
Correct |
6 ms |
2764 KB |
Output is correct |
31 |
Correct |
5 ms |
2764 KB |
Output is correct |
32 |
Correct |
4 ms |
2636 KB |
Output is correct |
33 |
Correct |
5 ms |
2764 KB |
Output is correct |
34 |
Correct |
18 ms |
3696 KB |
Output is correct |
35 |
Correct |
615 ms |
12716 KB |
Output is correct |
36 |
Correct |
573 ms |
11052 KB |
Output is correct |
37 |
Correct |
687 ms |
9752 KB |
Output is correct |
38 |
Correct |
783 ms |
9380 KB |
Output is correct |
39 |
Correct |
736 ms |
9156 KB |
Output is correct |
40 |
Correct |
642 ms |
8612 KB |
Output is correct |
41 |
Correct |
673 ms |
11912 KB |
Output is correct |
42 |
Correct |
780 ms |
12376 KB |
Output is correct |
43 |
Correct |
752 ms |
12200 KB |
Output is correct |
44 |
Correct |
797 ms |
9640 KB |
Output is correct |
45 |
Correct |
879 ms |
13064 KB |
Output is correct |
46 |
Correct |
917 ms |
12484 KB |
Output is correct |
47 |
Correct |
1050 ms |
10176 KB |
Output is correct |
48 |
Correct |
917 ms |
10320 KB |
Output is correct |
49 |
Correct |
124 ms |
10212 KB |
Output is correct |
50 |
Correct |
145 ms |
8320 KB |
Output is correct |
51 |
Correct |
502 ms |
11504 KB |
Output is correct |
52 |
Correct |
1151 ms |
15520 KB |
Output is correct |
53 |
Correct |
1098 ms |
14296 KB |
Output is correct |
54 |
Correct |
1037 ms |
17236 KB |
Output is correct |
55 |
Correct |
791 ms |
14088 KB |
Output is correct |
56 |
Correct |
1160 ms |
15112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
5 ms |
2636 KB |
Output is correct |
6 |
Correct |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
4 ms |
2764 KB |
Output is correct |
8 |
Correct |
6 ms |
2764 KB |
Output is correct |
9 |
Correct |
235 ms |
11908 KB |
Output is correct |
10 |
Correct |
631 ms |
13408 KB |
Output is correct |
11 |
Correct |
677 ms |
13928 KB |
Output is correct |
12 |
Correct |
774 ms |
14172 KB |
Output is correct |
13 |
Correct |
1212 ms |
14752 KB |
Output is correct |
14 |
Execution timed out |
2075 ms |
12272 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
5 ms |
2636 KB |
Output is correct |
7 |
Correct |
4 ms |
2636 KB |
Output is correct |
8 |
Correct |
4 ms |
2764 KB |
Output is correct |
9 |
Correct |
6 ms |
2764 KB |
Output is correct |
10 |
Correct |
235 ms |
11908 KB |
Output is correct |
11 |
Correct |
631 ms |
13408 KB |
Output is correct |
12 |
Correct |
677 ms |
13928 KB |
Output is correct |
13 |
Correct |
774 ms |
14172 KB |
Output is correct |
14 |
Correct |
1212 ms |
14752 KB |
Output is correct |
15 |
Execution timed out |
2075 ms |
12272 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |