# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
471199 |
2021-09-07T16:25:15 Z |
hoaphat1 |
Race (IOI11_race) |
C++17 |
|
646 ms |
101932 KB |
#include <bits/stdc++.h>
using namespace std;
int best_path(int n, int k, int edges[][2], int w[]) {
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < n - 1; i++) {
g[edges[i][0]].emplace_back(edges[i][1], w[i]);
g[edges[i][1]].emplace_back(edges[i][0], w[i]);
}
int ans = (int) 1e9;
vector<map<long long, int>> s(n);
vector<pair<long long, int>> offset(n);
function<void(int, int)> dfs = [&](int v, int p) {
s[v][0] = 0;
for (auto&x : g[v]) {
int u = x.first;
if (u == p) continue;
dfs(u, v);
offset[u].first += x.second;
offset[u].second++;
if ((int) s[v].size() < (int) s[u].size()) {
swap(s[v], s[u]);
swap(offset[v], offset[u]);
}
for (auto& now : s[u]) {
auto it = s[v].find(k - now.first - offset[v].first - offset[u].first);
if (it != s[v].end()) {
ans = min(ans, it->second + now.second + offset[v].second + offset[u].second);
}
}
for (auto& now : s[u]) {
int need = now.first + offset[u].first - offset[v].first;
if (!s[v].count(need)) s[v][need] = (int) 1e9;
s[v][need] = min(s[v][need], now.second + offset[u].second - offset[v].second);
}
}
};
dfs(0, -1);
if (ans == (int) 1e9) ans = -1;
return ans;
}
/*
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << best_path(3, 3, {{0, 1}, {1, 2}}, {1, 1});
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
528 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
584 KB |
Output is correct |
24 |
Correct |
2 ms |
588 KB |
Output is correct |
25 |
Correct |
2 ms |
588 KB |
Output is correct |
26 |
Correct |
2 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 |
2 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 |
2 ms |
588 KB |
Output is correct |
33 |
Correct |
3 ms |
696 KB |
Output is correct |
34 |
Correct |
2 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 |
588 KB |
Output is correct |
38 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
161 ms |
29252 KB |
Output is correct |
20 |
Correct |
187 ms |
29252 KB |
Output is correct |
21 |
Correct |
156 ms |
29024 KB |
Output is correct |
22 |
Correct |
156 ms |
28604 KB |
Output is correct |
23 |
Correct |
214 ms |
41348 KB |
Output is correct |
24 |
Correct |
173 ms |
31956 KB |
Output is correct |
25 |
Correct |
167 ms |
30852 KB |
Output is correct |
26 |
Correct |
94 ms |
39748 KB |
Output is correct |
27 |
Correct |
227 ms |
46380 KB |
Output is correct |
28 |
Correct |
499 ms |
92180 KB |
Output is correct |
29 |
Correct |
493 ms |
90176 KB |
Output is correct |
30 |
Correct |
225 ms |
47044 KB |
Output is correct |
31 |
Correct |
230 ms |
46908 KB |
Output is correct |
32 |
Correct |
335 ms |
46916 KB |
Output is correct |
33 |
Correct |
318 ms |
51968 KB |
Output is correct |
34 |
Correct |
568 ms |
84496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
528 KB |
Output is correct |
22 |
Correct |
2 ms |
716 KB |
Output is correct |
23 |
Correct |
2 ms |
584 KB |
Output is correct |
24 |
Correct |
2 ms |
588 KB |
Output is correct |
25 |
Correct |
2 ms |
588 KB |
Output is correct |
26 |
Correct |
2 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 |
2 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 |
2 ms |
588 KB |
Output is correct |
33 |
Correct |
3 ms |
696 KB |
Output is correct |
34 |
Correct |
2 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 |
588 KB |
Output is correct |
38 |
Correct |
2 ms |
588 KB |
Output is correct |
39 |
Correct |
161 ms |
29252 KB |
Output is correct |
40 |
Correct |
187 ms |
29252 KB |
Output is correct |
41 |
Correct |
156 ms |
29024 KB |
Output is correct |
42 |
Correct |
156 ms |
28604 KB |
Output is correct |
43 |
Correct |
214 ms |
41348 KB |
Output is correct |
44 |
Correct |
173 ms |
31956 KB |
Output is correct |
45 |
Correct |
167 ms |
30852 KB |
Output is correct |
46 |
Correct |
94 ms |
39748 KB |
Output is correct |
47 |
Correct |
227 ms |
46380 KB |
Output is correct |
48 |
Correct |
499 ms |
92180 KB |
Output is correct |
49 |
Correct |
493 ms |
90176 KB |
Output is correct |
50 |
Correct |
225 ms |
47044 KB |
Output is correct |
51 |
Correct |
230 ms |
46908 KB |
Output is correct |
52 |
Correct |
335 ms |
46916 KB |
Output is correct |
53 |
Correct |
318 ms |
51968 KB |
Output is correct |
54 |
Correct |
568 ms |
84496 KB |
Output is correct |
55 |
Correct |
24 ms |
4320 KB |
Output is correct |
56 |
Correct |
10 ms |
2940 KB |
Output is correct |
57 |
Correct |
100 ms |
27232 KB |
Output is correct |
58 |
Correct |
61 ms |
20716 KB |
Output is correct |
59 |
Correct |
154 ms |
46532 KB |
Output is correct |
60 |
Correct |
512 ms |
90924 KB |
Output is correct |
61 |
Correct |
314 ms |
50268 KB |
Output is correct |
62 |
Correct |
227 ms |
46904 KB |
Output is correct |
63 |
Correct |
322 ms |
47112 KB |
Output is correct |
64 |
Correct |
646 ms |
101932 KB |
Output is correct |
65 |
Correct |
645 ms |
99928 KB |
Output is correct |
66 |
Correct |
488 ms |
85540 KB |
Output is correct |
67 |
Correct |
258 ms |
41140 KB |
Output is correct |
68 |
Correct |
498 ms |
63460 KB |
Output is correct |
69 |
Correct |
504 ms |
68656 KB |
Output is correct |
70 |
Correct |
444 ms |
60664 KB |
Output is correct |