# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
349917 |
2021-01-18T16:59:11 Z |
Pety |
Race (IOI11_race) |
C++14 |
|
535 ms |
114284 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
const int N = 2e5 + 2;
vector<pair<int, long long> >G[N];
set<pair<long long, int> > s[N];
long long dist[N], edge[N], k;
long long ans;
///a + b - 2 * dist
void dfs (int nod, int p) {
s[nod].insert({dist[nod], edge[nod]});
for (auto it : G[nod]) {
if (it.first == p)
continue;
dist[it.first] = dist[nod] + it.second;
edge[it.first] = edge[nod] + 1;
dfs(it.first, nod);
if (s[nod].size() < s[it.first].size())
swap(s[nod], s[it.first]);
for (auto it2 : s[it.first]) {
auto meh = s[nod].lower_bound({k - it2.first + 2 * dist[nod], 0});
if (meh != s[nod].end() && meh->first + it2.first -2 * dist[nod] == k) {
ans = min(ans, it2.second + (*meh).second - 2 * edge[nod]);
}
}
for (auto it2 : s[it.first])
s[nod].insert(it2);
}
}
int best_path (int n, int K, int h[][2], int l[]) {
for (int i = 0; i < n - 1; i++) {
G[h[i][0]].push_back({h[i][1], l[i]});
G[h[i][1]].push_back({h[i][0], l[i]});
}
k = K;
ans = 1e9;
dfs(0, -1);
if (ans == 1e9)
return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14572 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14572 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
10 ms |
14464 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
13 ms |
14828 KB |
Output is correct |
23 |
Correct |
13 ms |
14828 KB |
Output is correct |
24 |
Correct |
13 ms |
14828 KB |
Output is correct |
25 |
Correct |
13 ms |
14976 KB |
Output is correct |
26 |
Correct |
12 ms |
14828 KB |
Output is correct |
27 |
Correct |
11 ms |
14572 KB |
Output is correct |
28 |
Correct |
13 ms |
14848 KB |
Output is correct |
29 |
Correct |
11 ms |
14700 KB |
Output is correct |
30 |
Correct |
11 ms |
14828 KB |
Output is correct |
31 |
Correct |
11 ms |
14828 KB |
Output is correct |
32 |
Correct |
11 ms |
14700 KB |
Output is correct |
33 |
Correct |
11 ms |
14828 KB |
Output is correct |
34 |
Correct |
11 ms |
14700 KB |
Output is correct |
35 |
Correct |
11 ms |
14700 KB |
Output is correct |
36 |
Correct |
11 ms |
14700 KB |
Output is correct |
37 |
Correct |
11 ms |
14700 KB |
Output is correct |
38 |
Correct |
11 ms |
14700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14572 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
185 ms |
42732 KB |
Output is correct |
20 |
Correct |
182 ms |
44012 KB |
Output is correct |
21 |
Correct |
181 ms |
43500 KB |
Output is correct |
22 |
Correct |
185 ms |
41964 KB |
Output is correct |
23 |
Correct |
213 ms |
56556 KB |
Output is correct |
24 |
Correct |
172 ms |
42732 KB |
Output is correct |
25 |
Correct |
183 ms |
47724 KB |
Output is correct |
26 |
Correct |
100 ms |
52992 KB |
Output is correct |
27 |
Correct |
279 ms |
55788 KB |
Output is correct |
28 |
Correct |
345 ms |
91756 KB |
Output is correct |
29 |
Correct |
347 ms |
90348 KB |
Output is correct |
30 |
Correct |
265 ms |
55788 KB |
Output is correct |
31 |
Correct |
254 ms |
55788 KB |
Output is correct |
32 |
Correct |
386 ms |
56044 KB |
Output is correct |
33 |
Correct |
298 ms |
57580 KB |
Output is correct |
34 |
Correct |
411 ms |
90348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14572 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
10 ms |
14464 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
13 ms |
14828 KB |
Output is correct |
23 |
Correct |
13 ms |
14828 KB |
Output is correct |
24 |
Correct |
13 ms |
14828 KB |
Output is correct |
25 |
Correct |
13 ms |
14976 KB |
Output is correct |
26 |
Correct |
12 ms |
14828 KB |
Output is correct |
27 |
Correct |
11 ms |
14572 KB |
Output is correct |
28 |
Correct |
13 ms |
14848 KB |
Output is correct |
29 |
Correct |
11 ms |
14700 KB |
Output is correct |
30 |
Correct |
11 ms |
14828 KB |
Output is correct |
31 |
Correct |
11 ms |
14828 KB |
Output is correct |
32 |
Correct |
11 ms |
14700 KB |
Output is correct |
33 |
Correct |
11 ms |
14828 KB |
Output is correct |
34 |
Correct |
11 ms |
14700 KB |
Output is correct |
35 |
Correct |
11 ms |
14700 KB |
Output is correct |
36 |
Correct |
11 ms |
14700 KB |
Output is correct |
37 |
Correct |
11 ms |
14700 KB |
Output is correct |
38 |
Correct |
11 ms |
14700 KB |
Output is correct |
39 |
Correct |
185 ms |
42732 KB |
Output is correct |
40 |
Correct |
182 ms |
44012 KB |
Output is correct |
41 |
Correct |
181 ms |
43500 KB |
Output is correct |
42 |
Correct |
185 ms |
41964 KB |
Output is correct |
43 |
Correct |
213 ms |
56556 KB |
Output is correct |
44 |
Correct |
172 ms |
42732 KB |
Output is correct |
45 |
Correct |
183 ms |
47724 KB |
Output is correct |
46 |
Correct |
100 ms |
52992 KB |
Output is correct |
47 |
Correct |
279 ms |
55788 KB |
Output is correct |
48 |
Correct |
345 ms |
91756 KB |
Output is correct |
49 |
Correct |
347 ms |
90348 KB |
Output is correct |
50 |
Correct |
265 ms |
55788 KB |
Output is correct |
51 |
Correct |
254 ms |
55788 KB |
Output is correct |
52 |
Correct |
386 ms |
56044 KB |
Output is correct |
53 |
Correct |
298 ms |
57580 KB |
Output is correct |
54 |
Correct |
411 ms |
90348 KB |
Output is correct |
55 |
Correct |
26 ms |
18156 KB |
Output is correct |
56 |
Correct |
20 ms |
16908 KB |
Output is correct |
57 |
Correct |
99 ms |
38892 KB |
Output is correct |
58 |
Correct |
64 ms |
29148 KB |
Output is correct |
59 |
Correct |
95 ms |
52944 KB |
Output is correct |
60 |
Correct |
333 ms |
90604 KB |
Output is correct |
61 |
Correct |
302 ms |
61548 KB |
Output is correct |
62 |
Correct |
250 ms |
55788 KB |
Output is correct |
63 |
Correct |
374 ms |
55916 KB |
Output is correct |
64 |
Correct |
535 ms |
114284 KB |
Output is correct |
65 |
Correct |
531 ms |
105836 KB |
Output is correct |
66 |
Correct |
367 ms |
86764 KB |
Output is correct |
67 |
Correct |
250 ms |
45524 KB |
Output is correct |
68 |
Correct |
496 ms |
70636 KB |
Output is correct |
69 |
Correct |
506 ms |
76012 KB |
Output is correct |
70 |
Correct |
451 ms |
68332 KB |
Output is correct |