#include "swap.h"
#include <bits/stdc++.h>
constexpr int N = 1e5;
int n, m;
std::vector<int> e[N];
std::vector<int> U, V, W, v;
std::vector<int> p;
std::vector<bool> vis;
bool have;
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());
}
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 (check(X, Y, v[l])) r = l;
if (r == v.size()) return -1;
return v[r];
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:103:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | if (r == v.size()) return -1;
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2516 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 |
4 ms |
2636 KB |
Output is correct |
6 |
Correct |
5 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2764 KB |
Output is correct |
8 |
Correct |
5 ms |
2656 KB |
Output is correct |
9 |
Correct |
261 ms |
13196 KB |
Output is correct |
10 |
Correct |
748 ms |
15068 KB |
Output is correct |
11 |
Correct |
851 ms |
15612 KB |
Output is correct |
12 |
Correct |
870 ms |
15788 KB |
Output is correct |
13 |
Correct |
1373 ms |
16296 KB |
Output is correct |
14 |
Execution timed out |
2077 ms |
13772 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2516 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Execution timed out |
2093 ms |
14920 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2516 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 |
4 ms |
2636 KB |
Output is correct |
6 |
Correct |
5 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2764 KB |
Output is correct |
8 |
Correct |
5 ms |
2656 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
4 ms |
2656 KB |
Output is correct |
11 |
Correct |
4 ms |
2732 KB |
Output is correct |
12 |
Correct |
4 ms |
2656 KB |
Output is correct |
13 |
Correct |
4 ms |
2636 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 |
2652 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 |
5 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 |
2764 KB |
Output is correct |
25 |
Correct |
6 ms |
2784 KB |
Output is correct |
26 |
Correct |
6 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 |
2 ms |
2516 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 |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2636 KB |
Output is correct |
8 |
Correct |
5 ms |
2764 KB |
Output is correct |
9 |
Correct |
5 ms |
2656 KB |
Output is correct |
10 |
Correct |
261 ms |
13196 KB |
Output is correct |
11 |
Correct |
748 ms |
15068 KB |
Output is correct |
12 |
Correct |
851 ms |
15612 KB |
Output is correct |
13 |
Correct |
870 ms |
15788 KB |
Output is correct |
14 |
Correct |
1373 ms |
16296 KB |
Output is correct |
15 |
Correct |
4 ms |
2656 KB |
Output is correct |
16 |
Correct |
4 ms |
2732 KB |
Output is correct |
17 |
Correct |
4 ms |
2656 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 |
2652 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 |
5 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 |
2764 KB |
Output is correct |
30 |
Correct |
6 ms |
2784 KB |
Output is correct |
31 |
Correct |
6 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 |
686 ms |
14260 KB |
Output is correct |
36 |
Correct |
652 ms |
12716 KB |
Output is correct |
37 |
Correct |
590 ms |
11344 KB |
Output is correct |
38 |
Correct |
774 ms |
10936 KB |
Output is correct |
39 |
Correct |
639 ms |
10688 KB |
Output is correct |
40 |
Correct |
580 ms |
10060 KB |
Output is correct |
41 |
Correct |
713 ms |
13612 KB |
Output is correct |
42 |
Correct |
734 ms |
13956 KB |
Output is correct |
43 |
Correct |
650 ms |
13868 KB |
Output is correct |
44 |
Correct |
665 ms |
11188 KB |
Output is correct |
45 |
Correct |
732 ms |
14468 KB |
Output is correct |
46 |
Correct |
707 ms |
13484 KB |
Output is correct |
47 |
Correct |
855 ms |
11052 KB |
Output is correct |
48 |
Correct |
735 ms |
11460 KB |
Output is correct |
49 |
Correct |
117 ms |
11588 KB |
Output is correct |
50 |
Correct |
126 ms |
9668 KB |
Output is correct |
51 |
Correct |
467 ms |
12872 KB |
Output is correct |
52 |
Correct |
1106 ms |
16800 KB |
Output is correct |
53 |
Correct |
1087 ms |
15888 KB |
Output is correct |
54 |
Correct |
999 ms |
18880 KB |
Output is correct |
55 |
Correct |
791 ms |
14988 KB |
Output is correct |
56 |
Correct |
1016 ms |
16568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2516 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 |
4 ms |
2636 KB |
Output is correct |
6 |
Correct |
5 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2764 KB |
Output is correct |
8 |
Correct |
5 ms |
2656 KB |
Output is correct |
9 |
Correct |
261 ms |
13196 KB |
Output is correct |
10 |
Correct |
748 ms |
15068 KB |
Output is correct |
11 |
Correct |
851 ms |
15612 KB |
Output is correct |
12 |
Correct |
870 ms |
15788 KB |
Output is correct |
13 |
Correct |
1373 ms |
16296 KB |
Output is correct |
14 |
Execution timed out |
2077 ms |
13772 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 |
2516 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 |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2636 KB |
Output is correct |
8 |
Correct |
5 ms |
2764 KB |
Output is correct |
9 |
Correct |
5 ms |
2656 KB |
Output is correct |
10 |
Correct |
261 ms |
13196 KB |
Output is correct |
11 |
Correct |
748 ms |
15068 KB |
Output is correct |
12 |
Correct |
851 ms |
15612 KB |
Output is correct |
13 |
Correct |
870 ms |
15788 KB |
Output is correct |
14 |
Correct |
1373 ms |
16296 KB |
Output is correct |
15 |
Execution timed out |
2077 ms |
13772 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |