#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define db double
#define ll long long
#define ar array
template<typename T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int INF = 1e9;
vector<vector<ar<int, 3>>> adj;
int n, m;
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N, m = M;
adj.resize(N + 1);
for (int i = 0; i < M; i++) {
adj[U[i]].push_back({V[i], W[i], i});
adj[V[i]].push_back({U[i], W[i], i});
}
}
int getMinimumFuelCapacity(int X, int Y) {
auto good = [&](int mid) -> bool {
vector<bool> vis(n+1);
auto dfs = [&](auto&& s, int v) -> void {
vis[v] = 1;
for (auto [u, w, idx] : adj[v]) if (w <= mid && !vis[u]) s(s, u);
};
dfs(dfs, X);
if (!vis[Y]) return 0;
bool ok = 1;
for (int i = 1; i <= n; i++) if (vis[i]) {
int deg = 0;
for (auto x : adj[i]) deg += x[1] <= mid && vis[x[0]];
if (deg > 2) {
return 1;
}
if (deg == 1) ok = 0;
}
return ok;
};
int l = 1, r = 1e9, ans = 1e9;
if (!good(r)) return -1;
while (l <= r) {
int mid = (l+r)/2;
if (good(mid)) ans = mid, r = mid-1;
else l = mid+1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
33 ms |
8316 KB |
Output is correct |
10 |
Correct |
53 ms |
10176 KB |
Output is correct |
11 |
Correct |
53 ms |
9976 KB |
Output is correct |
12 |
Correct |
58 ms |
10424 KB |
Output is correct |
13 |
Correct |
56 ms |
10680 KB |
Output is correct |
14 |
Execution timed out |
2104 ms |
8928 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2028 ms |
12508 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 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 |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
448 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
5 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
33 ms |
8316 KB |
Output is correct |
11 |
Correct |
53 ms |
10176 KB |
Output is correct |
12 |
Correct |
53 ms |
9976 KB |
Output is correct |
13 |
Correct |
58 ms |
10424 KB |
Output is correct |
14 |
Correct |
56 ms |
10680 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 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 |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 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 |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
448 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
5 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
11 ms |
1884 KB |
Output is correct |
35 |
Correct |
479 ms |
10528 KB |
Output is correct |
36 |
Correct |
459 ms |
9808 KB |
Output is correct |
37 |
Correct |
453 ms |
10032 KB |
Output is correct |
38 |
Correct |
512 ms |
9812 KB |
Output is correct |
39 |
Correct |
422 ms |
9556 KB |
Output is correct |
40 |
Correct |
466 ms |
9296 KB |
Output is correct |
41 |
Correct |
388 ms |
10252 KB |
Output is correct |
42 |
Correct |
538 ms |
10260 KB |
Output is correct |
43 |
Correct |
386 ms |
10816 KB |
Output is correct |
44 |
Correct |
246 ms |
11856 KB |
Output is correct |
45 |
Correct |
460 ms |
14416 KB |
Output is correct |
46 |
Correct |
507 ms |
10332 KB |
Output is correct |
47 |
Correct |
509 ms |
9808 KB |
Output is correct |
48 |
Correct |
450 ms |
10700 KB |
Output is correct |
49 |
Correct |
81 ms |
13648 KB |
Output is correct |
50 |
Correct |
92 ms |
10580 KB |
Output is correct |
51 |
Correct |
281 ms |
12372 KB |
Output is correct |
52 |
Correct |
441 ms |
15956 KB |
Output is correct |
53 |
Correct |
291 ms |
17064 KB |
Output is correct |
54 |
Correct |
1116 ms |
18820 KB |
Output is correct |
55 |
Correct |
485 ms |
10940 KB |
Output is correct |
56 |
Correct |
640 ms |
16724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
33 ms |
8316 KB |
Output is correct |
10 |
Correct |
53 ms |
10176 KB |
Output is correct |
11 |
Correct |
53 ms |
9976 KB |
Output is correct |
12 |
Correct |
58 ms |
10424 KB |
Output is correct |
13 |
Correct |
56 ms |
10680 KB |
Output is correct |
14 |
Execution timed out |
2104 ms |
8928 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
33 ms |
8316 KB |
Output is correct |
11 |
Correct |
53 ms |
10176 KB |
Output is correct |
12 |
Correct |
53 ms |
9976 KB |
Output is correct |
13 |
Correct |
58 ms |
10424 KB |
Output is correct |
14 |
Correct |
56 ms |
10680 KB |
Output is correct |
15 |
Execution timed out |
2104 ms |
8928 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |