#include "swap.h"
#include <bits/stdc++.h>
constexpr int N = 1e5;
std::vector<int> e[N];
std::vector<int> U, V, W;
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;
}
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];
}
y = Y;
std::vector<bool> bad(n);
for (auto x : got) {
bad[x] = true;
y = x;
}
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]]
&& !((U[i] == X && V[i] == Y) || (U[i] == Y && V[i] == X))) {
e[U[i]].emplace_back(V[i]);
e[V[i]].emplace_back(U[i]);
}
}
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) {
std::vector<int> v = W;
sort(v.begin(), v.end());
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:84:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | if (r == v.size()) return -1;
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2632 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
4 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 |
6 ms |
2636 KB |
Output is correct |
9 |
Correct |
213 ms |
11560 KB |
Output is correct |
10 |
Correct |
649 ms |
12892 KB |
Output is correct |
11 |
Correct |
707 ms |
13544 KB |
Output is correct |
12 |
Correct |
788 ms |
13640 KB |
Output is correct |
13 |
Correct |
1193 ms |
14116 KB |
Output is correct |
14 |
Execution timed out |
2092 ms |
12064 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Execution timed out |
2082 ms |
11092 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2632 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
4 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 |
6 ms |
2636 KB |
Output is correct |
9 |
Correct |
5 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 |
4 ms |
2636 KB |
Output is correct |
14 |
Correct |
4 ms |
2696 KB |
Output is correct |
15 |
Correct |
4 ms |
2636 KB |
Output is correct |
16 |
Correct |
7 ms |
2636 KB |
Output is correct |
17 |
Correct |
6 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 |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2636 KB |
Output is correct |
25 |
Incorrect |
6 ms |
2748 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 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 |
2 ms |
2632 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2636 KB |
Output is correct |
8 |
Correct |
4 ms |
2636 KB |
Output is correct |
9 |
Correct |
6 ms |
2636 KB |
Output is correct |
10 |
Correct |
213 ms |
11560 KB |
Output is correct |
11 |
Correct |
649 ms |
12892 KB |
Output is correct |
12 |
Correct |
707 ms |
13544 KB |
Output is correct |
13 |
Correct |
788 ms |
13640 KB |
Output is correct |
14 |
Correct |
1193 ms |
14116 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 |
2696 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
7 ms |
2636 KB |
Output is correct |
22 |
Correct |
6 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 |
2688 KB |
Output is correct |
29 |
Correct |
6 ms |
2636 KB |
Output is correct |
30 |
Incorrect |
6 ms |
2748 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2632 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
4 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 |
6 ms |
2636 KB |
Output is correct |
9 |
Correct |
213 ms |
11560 KB |
Output is correct |
10 |
Correct |
649 ms |
12892 KB |
Output is correct |
11 |
Correct |
707 ms |
13544 KB |
Output is correct |
12 |
Correct |
788 ms |
13640 KB |
Output is correct |
13 |
Correct |
1193 ms |
14116 KB |
Output is correct |
14 |
Execution timed out |
2092 ms |
12064 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 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 |
2 ms |
2632 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2636 KB |
Output is correct |
8 |
Correct |
4 ms |
2636 KB |
Output is correct |
9 |
Correct |
6 ms |
2636 KB |
Output is correct |
10 |
Correct |
213 ms |
11560 KB |
Output is correct |
11 |
Correct |
649 ms |
12892 KB |
Output is correct |
12 |
Correct |
707 ms |
13544 KB |
Output is correct |
13 |
Correct |
788 ms |
13640 KB |
Output is correct |
14 |
Correct |
1193 ms |
14116 KB |
Output is correct |
15 |
Execution timed out |
2092 ms |
12064 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |