# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
515843 |
2022-01-19T21:34:00 Z |
tabr |
Race (IOI11_race) |
C++17 |
|
569 ms |
97144 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int best_path(int n, int k, int h[][2], int l[]) {
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
g[h[i][0]].emplace_back(i);
g[h[i][1]].emplace_back(i);
}
int ans = n;
vector<int> depth(n);
vector<long long> dist(n);
vector<map<long long, int>> a(n);
auto dfs = [&](auto dfs, int v, int p) -> void {
vector<int> c;
for (int id : g[v]) {
int to = v ^ h[id][0] ^ h[id][1];
if (to == p) {
continue;
}
c.emplace_back(to);
depth[to] = depth[v] + 1;
dist[to] = dist[v] + l[id];
dfs(dfs, to, v);
long long t = dist[v] + k;
if (a[to].count(t)) {
ans = min(ans, a[to][t] - depth[v]);
}
}
if (c.empty()) {
a[v][dist[v]] = depth[v];
return;
}
sort(c.begin(), c.end(), [&](int i, int j) {
return a[i].size() > a[j].size();
});
swap(a[v], a[c[0]]);
a[v][dist[v]] = depth[v];
for (int i = 1; i < (int) c.size(); i++) {
for (auto q : a[c[i]]) {
long long t = 2 * dist[v] - q.first + k;
if (a[v].count(t)) {
ans = min(ans, a[v][t] + q.second - 2 * depth[v]);
}
}
for (auto q : a[c[i]]) {
if (!a[v].count(q.first)) {
a[v][q.first] = n;
}
a[v][q.first] = min(a[v][q.first], q.second);
}
}
};
dfs(dfs, 0, -1);
if (ans == n) {
ans = -1;
}
return ans;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
588 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
2 ms |
588 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
588 KB |
Output is correct |
30 |
Correct |
2 ms |
588 KB |
Output is correct |
31 |
Correct |
2 ms |
588 KB |
Output is correct |
32 |
Correct |
3 ms |
588 KB |
Output is correct |
33 |
Correct |
2 ms |
588 KB |
Output is correct |
34 |
Correct |
1 ms |
588 KB |
Output is correct |
35 |
Correct |
1 ms |
588 KB |
Output is correct |
36 |
Correct |
1 ms |
588 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
147 ms |
23936 KB |
Output is correct |
20 |
Correct |
143 ms |
23848 KB |
Output is correct |
21 |
Correct |
125 ms |
23764 KB |
Output is correct |
22 |
Correct |
157 ms |
24272 KB |
Output is correct |
23 |
Correct |
188 ms |
36800 KB |
Output is correct |
24 |
Correct |
153 ms |
30184 KB |
Output is correct |
25 |
Correct |
101 ms |
30468 KB |
Output is correct |
26 |
Correct |
61 ms |
45836 KB |
Output is correct |
27 |
Correct |
204 ms |
38836 KB |
Output is correct |
28 |
Correct |
237 ms |
97144 KB |
Output is correct |
29 |
Correct |
238 ms |
93636 KB |
Output is correct |
30 |
Correct |
207 ms |
38980 KB |
Output is correct |
31 |
Correct |
199 ms |
38816 KB |
Output is correct |
32 |
Correct |
258 ms |
38832 KB |
Output is correct |
33 |
Correct |
222 ms |
38472 KB |
Output is correct |
34 |
Correct |
403 ms |
70428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
588 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
2 ms |
588 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
588 KB |
Output is correct |
30 |
Correct |
2 ms |
588 KB |
Output is correct |
31 |
Correct |
2 ms |
588 KB |
Output is correct |
32 |
Correct |
3 ms |
588 KB |
Output is correct |
33 |
Correct |
2 ms |
588 KB |
Output is correct |
34 |
Correct |
1 ms |
588 KB |
Output is correct |
35 |
Correct |
1 ms |
588 KB |
Output is correct |
36 |
Correct |
1 ms |
588 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
588 KB |
Output is correct |
39 |
Correct |
147 ms |
23936 KB |
Output is correct |
40 |
Correct |
143 ms |
23848 KB |
Output is correct |
41 |
Correct |
125 ms |
23764 KB |
Output is correct |
42 |
Correct |
157 ms |
24272 KB |
Output is correct |
43 |
Correct |
188 ms |
36800 KB |
Output is correct |
44 |
Correct |
153 ms |
30184 KB |
Output is correct |
45 |
Correct |
101 ms |
30468 KB |
Output is correct |
46 |
Correct |
61 ms |
45836 KB |
Output is correct |
47 |
Correct |
204 ms |
38836 KB |
Output is correct |
48 |
Correct |
237 ms |
97144 KB |
Output is correct |
49 |
Correct |
238 ms |
93636 KB |
Output is correct |
50 |
Correct |
207 ms |
38980 KB |
Output is correct |
51 |
Correct |
199 ms |
38816 KB |
Output is correct |
52 |
Correct |
258 ms |
38832 KB |
Output is correct |
53 |
Correct |
222 ms |
38472 KB |
Output is correct |
54 |
Correct |
403 ms |
70428 KB |
Output is correct |
55 |
Correct |
15 ms |
3660 KB |
Output is correct |
56 |
Correct |
8 ms |
2380 KB |
Output is correct |
57 |
Correct |
75 ms |
21928 KB |
Output is correct |
58 |
Correct |
56 ms |
19756 KB |
Output is correct |
59 |
Correct |
76 ms |
48796 KB |
Output is correct |
60 |
Correct |
234 ms |
94916 KB |
Output is correct |
61 |
Correct |
234 ms |
42232 KB |
Output is correct |
62 |
Correct |
202 ms |
38776 KB |
Output is correct |
63 |
Correct |
310 ms |
38928 KB |
Output is correct |
64 |
Correct |
543 ms |
88548 KB |
Output is correct |
65 |
Correct |
569 ms |
88764 KB |
Output is correct |
66 |
Correct |
249 ms |
86012 KB |
Output is correct |
67 |
Correct |
223 ms |
39400 KB |
Output is correct |
68 |
Correct |
386 ms |
56660 KB |
Output is correct |
69 |
Correct |
402 ms |
57356 KB |
Output is correct |
70 |
Correct |
360 ms |
54248 KB |
Output is correct |