# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
927945 |
2024-02-15T14:28:00 Z |
TAhmed33 |
Race (IOI11_race) |
C++ |
|
751 ms |
45336 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 2e5 + 24;
int sze[MAX];
bitset <MAX> vis;
int k;
vector <pair <int, int>> adj[MAX];
void calc (int pos, int par) {
sze[pos] = 1;
for (auto j : adj[pos]) {
if (j.first == par || vis[j.first]) continue;
calc(j.first, pos);
sze[pos] += sze[j.first];
}
}
int find (int pos, int par, int kk) {
for (auto j : adj[pos]) {
if (j.first == par) continue;
if (vis[j.first]) continue;
if (sze[j.first] > (kk >> 1)) return find(j.first, pos, kk);
}
return pos;
}
int mn = 1e10;
map <int, int> cnt;
void ll2 (int pos, int par, int dep, int dist) {
if (dist > k) return;
if (cnt.count(k - dist)) mn = min(cnt[k - dist] + dep, mn);
for (auto j : adj[pos]) {
if (j.first != par && !vis[j.first]) {
ll2(j.first, pos, dep + 1, dist + j.second);
}
}
}
void ll (int pos, int par, int dep, int dist) {
if (dist > k) return;
if (cnt.count(dist)) cnt[dist] = min(cnt[dist], dep);
else cnt[dist] = dep;
for (auto j : adj[pos]) {
if (j.first != par && !vis[j.first]) {
ll(j.first, pos, dep + 1, dist + j.second);
}
}
}
void decomp (int pos) {
calc(pos, -1);
int c = find(pos, -1, sze[pos]);
vis[c] = 1;
cnt[0] = 0;
for (auto j : adj[c]) {
if (vis[j.first]) continue;
ll2(j.first, c, 1, j.second);
ll(j.first, c, 1, j.second);
}
cnt.clear();
for (auto i : adj[c]) {
if (!vis[i.first]) {
decomp(i.first);
}
}
}
int32_t best_path (int32_t n, int32_t K, int32_t h[][2], int32_t l[]) {
k = K;
for (int i = 0; i + 1 < n; i++) {
adj[h[i][0] + 1].push_back({h[i][1] + 1, l[i]});
adj[h[i][1] + 1].push_back({h[i][0] + 1, l[i]});
}
for (int i = 1; i <= n; i++) {
vis[i] = 0;
}
decomp(1);
return (mn >= 1e10 ? -1 : mn);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
9048 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
3 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
9048 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
3 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8792 KB |
Output is correct |
23 |
Correct |
3 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8792 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
2 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
9048 KB |
Output is correct |
29 |
Correct |
3 ms |
8796 KB |
Output is correct |
30 |
Correct |
3 ms |
8796 KB |
Output is correct |
31 |
Correct |
3 ms |
8796 KB |
Output is correct |
32 |
Correct |
3 ms |
8796 KB |
Output is correct |
33 |
Correct |
3 ms |
8796 KB |
Output is correct |
34 |
Correct |
2 ms |
8796 KB |
Output is correct |
35 |
Correct |
2 ms |
8796 KB |
Output is correct |
36 |
Correct |
2 ms |
8792 KB |
Output is correct |
37 |
Correct |
2 ms |
8796 KB |
Output is correct |
38 |
Correct |
3 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
9048 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
3 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
158 ms |
17176 KB |
Output is correct |
20 |
Correct |
145 ms |
16884 KB |
Output is correct |
21 |
Correct |
169 ms |
16892 KB |
Output is correct |
22 |
Correct |
157 ms |
16928 KB |
Output is correct |
23 |
Correct |
58 ms |
17236 KB |
Output is correct |
24 |
Correct |
55 ms |
16624 KB |
Output is correct |
25 |
Correct |
108 ms |
19804 KB |
Output is correct |
26 |
Correct |
87 ms |
22760 KB |
Output is correct |
27 |
Correct |
169 ms |
23404 KB |
Output is correct |
28 |
Correct |
185 ms |
34388 KB |
Output is correct |
29 |
Correct |
197 ms |
33360 KB |
Output is correct |
30 |
Correct |
135 ms |
23368 KB |
Output is correct |
31 |
Correct |
163 ms |
23640 KB |
Output is correct |
32 |
Correct |
161 ms |
23444 KB |
Output is correct |
33 |
Correct |
177 ms |
22096 KB |
Output is correct |
34 |
Correct |
126 ms |
22352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
9048 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
3 ms |
8796 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8792 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8792 KB |
Output is correct |
23 |
Correct |
3 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8792 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
2 ms |
8796 KB |
Output is correct |
28 |
Correct |
2 ms |
9048 KB |
Output is correct |
29 |
Correct |
3 ms |
8796 KB |
Output is correct |
30 |
Correct |
3 ms |
8796 KB |
Output is correct |
31 |
Correct |
3 ms |
8796 KB |
Output is correct |
32 |
Correct |
3 ms |
8796 KB |
Output is correct |
33 |
Correct |
3 ms |
8796 KB |
Output is correct |
34 |
Correct |
2 ms |
8796 KB |
Output is correct |
35 |
Correct |
2 ms |
8796 KB |
Output is correct |
36 |
Correct |
2 ms |
8792 KB |
Output is correct |
37 |
Correct |
2 ms |
8796 KB |
Output is correct |
38 |
Correct |
3 ms |
8796 KB |
Output is correct |
39 |
Correct |
158 ms |
17176 KB |
Output is correct |
40 |
Correct |
145 ms |
16884 KB |
Output is correct |
41 |
Correct |
169 ms |
16892 KB |
Output is correct |
42 |
Correct |
157 ms |
16928 KB |
Output is correct |
43 |
Correct |
58 ms |
17236 KB |
Output is correct |
44 |
Correct |
55 ms |
16624 KB |
Output is correct |
45 |
Correct |
108 ms |
19804 KB |
Output is correct |
46 |
Correct |
87 ms |
22760 KB |
Output is correct |
47 |
Correct |
169 ms |
23404 KB |
Output is correct |
48 |
Correct |
185 ms |
34388 KB |
Output is correct |
49 |
Correct |
197 ms |
33360 KB |
Output is correct |
50 |
Correct |
135 ms |
23368 KB |
Output is correct |
51 |
Correct |
163 ms |
23640 KB |
Output is correct |
52 |
Correct |
161 ms |
23444 KB |
Output is correct |
53 |
Correct |
177 ms |
22096 KB |
Output is correct |
54 |
Correct |
126 ms |
22352 KB |
Output is correct |
55 |
Correct |
15 ms |
9564 KB |
Output is correct |
56 |
Correct |
12 ms |
9376 KB |
Output is correct |
57 |
Correct |
111 ms |
17236 KB |
Output is correct |
58 |
Correct |
43 ms |
16512 KB |
Output is correct |
59 |
Correct |
229 ms |
27216 KB |
Output is correct |
60 |
Correct |
591 ms |
45336 KB |
Output is correct |
61 |
Correct |
261 ms |
23376 KB |
Output is correct |
62 |
Correct |
216 ms |
23520 KB |
Output is correct |
63 |
Correct |
251 ms |
23636 KB |
Output is correct |
64 |
Correct |
751 ms |
28648 KB |
Output is correct |
65 |
Correct |
138 ms |
22848 KB |
Output is correct |
66 |
Correct |
414 ms |
31672 KB |
Output is correct |
67 |
Correct |
94 ms |
21932 KB |
Output is correct |
68 |
Correct |
295 ms |
27472 KB |
Output is correct |
69 |
Correct |
285 ms |
27220 KB |
Output is correct |
70 |
Correct |
253 ms |
26704 KB |
Output is correct |