# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
329291 |
2020-11-20T08:36:26 Z |
ryangohca |
Race (IOI11_race) |
C++17 |
|
458 ms |
108976 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<long long, long long>
long long n, k;
vector<pii> adjlist[200000];
long long dep[200000];
long long off[200000];
long long ans = 1<<30;
set<pii> *dfs(long long n, long long p, long long d){
dep[n] = d;
set<pii> *cur = new set<pii>();
for (auto [i, cost] : adjlist[n]){
if (i == p) continue;
set<pii> *child = dfs(i, n, d + 1);
if (cur->size() < child->size()){
for (auto [path, depth] : *cur){
auto itr = child->lower_bound({k - (path + off[n]) - cost - off[i], 0});
if (itr != child->end()){
if ((*itr).first == k - (path + off[n]) - cost - off[i]){
ans = min(ans, (*itr).second + depth - 2*d);
}
}
}
for (auto [path, depth] : *cur){
long long newp = path + off[n] - off[i] - cost;
child->insert({newp, depth});
}
off[n] = off[i] + cost;
swap(child, cur);
} else {
for (auto [path, depth] : *child){
long long actual = path + off[i] + cost;
auto itr = cur->lower_bound({k - actual - off[n], 0});
if (itr != cur->end()){
if ((*itr).first == k - actual - off[n]){
ans = min(ans, (*itr).second + depth - 2*d);
}
}
}
for (auto [path, depth] : *child){
cur->insert({path + off[i] + cost - off[n], depth});
}
}
}
cur->insert({-off[n], d});
auto itr = cur->lower_bound({k - off[n], 0});
if (itr != cur->end()){
if ((*itr).first == k - off[n]){
ans = min(ans, (*itr).second - d);
}
}
return cur;
}
int best_path(int N, int K, int H[][2], int L[]){
n = N;
k = K;
for (int i = 0; i < N - 1; i++){
adjlist[H[i][0]].push_back({H[i][1], L[i]});
adjlist[H[i][1]].push_back({H[i][0], L[i]});
}
dfs(0, -1, 0);
if (ans == (1<<30)) return -1;
else return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5228 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5228 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
4 ms |
5100 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
5 ms |
5356 KB |
Output is correct |
22 |
Correct |
5 ms |
5368 KB |
Output is correct |
23 |
Correct |
5 ms |
5356 KB |
Output is correct |
24 |
Correct |
5 ms |
5376 KB |
Output is correct |
25 |
Correct |
5 ms |
5356 KB |
Output is correct |
26 |
Correct |
5 ms |
5356 KB |
Output is correct |
27 |
Correct |
5 ms |
5228 KB |
Output is correct |
28 |
Correct |
5 ms |
5356 KB |
Output is correct |
29 |
Correct |
5 ms |
5356 KB |
Output is correct |
30 |
Correct |
5 ms |
5356 KB |
Output is correct |
31 |
Correct |
5 ms |
5356 KB |
Output is correct |
32 |
Correct |
5 ms |
5356 KB |
Output is correct |
33 |
Correct |
6 ms |
5484 KB |
Output is correct |
34 |
Correct |
5 ms |
5356 KB |
Output is correct |
35 |
Correct |
5 ms |
5356 KB |
Output is correct |
36 |
Correct |
4 ms |
5356 KB |
Output is correct |
37 |
Correct |
5 ms |
5356 KB |
Output is correct |
38 |
Correct |
8 ms |
5356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5228 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
149 ms |
36716 KB |
Output is correct |
20 |
Correct |
157 ms |
36588 KB |
Output is correct |
21 |
Correct |
155 ms |
36332 KB |
Output is correct |
22 |
Correct |
154 ms |
35292 KB |
Output is correct |
23 |
Correct |
171 ms |
50156 KB |
Output is correct |
24 |
Correct |
128 ms |
38636 KB |
Output is correct |
25 |
Correct |
131 ms |
40012 KB |
Output is correct |
26 |
Correct |
93 ms |
46976 KB |
Output is correct |
27 |
Correct |
248 ms |
52588 KB |
Output is correct |
28 |
Correct |
280 ms |
88812 KB |
Output is correct |
29 |
Correct |
272 ms |
86724 KB |
Output is correct |
30 |
Correct |
247 ms |
52588 KB |
Output is correct |
31 |
Correct |
249 ms |
52584 KB |
Output is correct |
32 |
Correct |
301 ms |
52836 KB |
Output is correct |
33 |
Correct |
245 ms |
48364 KB |
Output is correct |
34 |
Correct |
348 ms |
81132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5120 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
4 ms |
5228 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
4 ms |
5100 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
5 ms |
5356 KB |
Output is correct |
22 |
Correct |
5 ms |
5368 KB |
Output is correct |
23 |
Correct |
5 ms |
5356 KB |
Output is correct |
24 |
Correct |
5 ms |
5376 KB |
Output is correct |
25 |
Correct |
5 ms |
5356 KB |
Output is correct |
26 |
Correct |
5 ms |
5356 KB |
Output is correct |
27 |
Correct |
5 ms |
5228 KB |
Output is correct |
28 |
Correct |
5 ms |
5356 KB |
Output is correct |
29 |
Correct |
5 ms |
5356 KB |
Output is correct |
30 |
Correct |
5 ms |
5356 KB |
Output is correct |
31 |
Correct |
5 ms |
5356 KB |
Output is correct |
32 |
Correct |
5 ms |
5356 KB |
Output is correct |
33 |
Correct |
6 ms |
5484 KB |
Output is correct |
34 |
Correct |
5 ms |
5356 KB |
Output is correct |
35 |
Correct |
5 ms |
5356 KB |
Output is correct |
36 |
Correct |
4 ms |
5356 KB |
Output is correct |
37 |
Correct |
5 ms |
5356 KB |
Output is correct |
38 |
Correct |
8 ms |
5356 KB |
Output is correct |
39 |
Correct |
149 ms |
36716 KB |
Output is correct |
40 |
Correct |
157 ms |
36588 KB |
Output is correct |
41 |
Correct |
155 ms |
36332 KB |
Output is correct |
42 |
Correct |
154 ms |
35292 KB |
Output is correct |
43 |
Correct |
171 ms |
50156 KB |
Output is correct |
44 |
Correct |
128 ms |
38636 KB |
Output is correct |
45 |
Correct |
131 ms |
40012 KB |
Output is correct |
46 |
Correct |
93 ms |
46976 KB |
Output is correct |
47 |
Correct |
248 ms |
52588 KB |
Output is correct |
48 |
Correct |
280 ms |
88812 KB |
Output is correct |
49 |
Correct |
272 ms |
86724 KB |
Output is correct |
50 |
Correct |
247 ms |
52588 KB |
Output is correct |
51 |
Correct |
249 ms |
52584 KB |
Output is correct |
52 |
Correct |
301 ms |
52836 KB |
Output is correct |
53 |
Correct |
245 ms |
48364 KB |
Output is correct |
54 |
Correct |
348 ms |
81132 KB |
Output is correct |
55 |
Correct |
17 ms |
8940 KB |
Output is correct |
56 |
Correct |
12 ms |
7660 KB |
Output is correct |
57 |
Correct |
84 ms |
31852 KB |
Output is correct |
58 |
Correct |
64 ms |
25436 KB |
Output is correct |
59 |
Correct |
87 ms |
46792 KB |
Output is correct |
60 |
Correct |
254 ms |
87148 KB |
Output is correct |
61 |
Correct |
302 ms |
58348 KB |
Output is correct |
62 |
Correct |
237 ms |
52716 KB |
Output is correct |
63 |
Correct |
303 ms |
52716 KB |
Output is correct |
64 |
Correct |
458 ms |
108976 KB |
Output is correct |
65 |
Correct |
457 ms |
101868 KB |
Output is correct |
66 |
Correct |
279 ms |
82028 KB |
Output is correct |
67 |
Correct |
210 ms |
48596 KB |
Output is correct |
68 |
Correct |
385 ms |
69656 KB |
Output is correct |
69 |
Correct |
420 ms |
75264 KB |
Output is correct |
70 |
Correct |
371 ms |
66644 KB |
Output is correct |