# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
887744 |
2023-12-15T07:10:24 Z |
artixkrishna |
Race (IOI11_race) |
C++14 |
|
364 ms |
86704 KB |
#include <bits/stdc++.h>
#include "race.h"
#define sz(x) (int)x.size()
using namespace std;
using pii = pair<int, int>;
int ans = 1e9, k;
vector<vector<pii> > graph;
vector<int> dist, edges;
vector<map<int, int> > sets;
void precomp(int u, int p, int e, int d) {
edges[u] = e;
dist[u] = d;
for(auto &[v, w] : graph[u]) {
if(v == p) continue;
precomp(v, u, e + 1, d + w);
}
}
void dfs(int u, int p) {
sets[u][dist[u]] = edges[u];
for(auto &[v, w] : graph[u]) {
if(v == p) continue;
dfs(v, u);
if(sz(sets[u]) < sz(sets[v])) swap(sets[u], sets[v]);
for(auto &x : sets[v])
if(sets[u].count(k + 2 * dist[u] - x.first))
ans = min(ans, x.second + sets[u][k+2*dist[u]-x.first] - 2 * edges[u]);
for(auto &x : sets[v]) {
if(sets[u].count(x.first)) sets[u][x.first] = min(sets[u][x.first], x.second);
else sets[u][x.first] = x.second;
}
}
}
int best_path(int N, int K, int H[][2], int L[]) {
k = K;
graph.resize(N);
dist.resize(N);
edges.resize(N);
sets.resize(N);
for(int i=0; i<N-1; i++) {
graph[H[i][0]].push_back({ H[i][1], L[i] });
graph[H[i][1]].push_back({ H[i][0], L[i] });
}
precomp(0, 0, 0, 0);
dfs(0, 0);
return (ans == 1e9 ? -1 : ans);
}
Compilation message
race.cpp: In function 'void precomp(int, int, int, int)':
race.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
17 | for(auto &[v, w] : graph[u]) {
| ^
race.cpp: In function 'void dfs(int, int)':
race.cpp:25:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | for(auto &[v, w] : graph[u]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2764 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2660 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2756 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2648 KB |
Output is correct |
37 |
Correct |
1 ms |
2500 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
102 ms |
29240 KB |
Output is correct |
20 |
Correct |
87 ms |
29008 KB |
Output is correct |
21 |
Correct |
95 ms |
29012 KB |
Output is correct |
22 |
Correct |
96 ms |
28720 KB |
Output is correct |
23 |
Correct |
124 ms |
38416 KB |
Output is correct |
24 |
Correct |
98 ms |
31396 KB |
Output is correct |
25 |
Correct |
81 ms |
30284 KB |
Output is correct |
26 |
Correct |
47 ms |
37360 KB |
Output is correct |
27 |
Correct |
160 ms |
44976 KB |
Output is correct |
28 |
Correct |
231 ms |
79660 KB |
Output is correct |
29 |
Correct |
225 ms |
77960 KB |
Output is correct |
30 |
Correct |
139 ms |
45004 KB |
Output is correct |
31 |
Correct |
140 ms |
44912 KB |
Output is correct |
32 |
Correct |
182 ms |
45144 KB |
Output is correct |
33 |
Correct |
211 ms |
48448 KB |
Output is correct |
34 |
Correct |
268 ms |
73288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2764 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2660 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2756 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2648 KB |
Output is correct |
37 |
Correct |
1 ms |
2500 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
102 ms |
29240 KB |
Output is correct |
40 |
Correct |
87 ms |
29008 KB |
Output is correct |
41 |
Correct |
95 ms |
29012 KB |
Output is correct |
42 |
Correct |
96 ms |
28720 KB |
Output is correct |
43 |
Correct |
124 ms |
38416 KB |
Output is correct |
44 |
Correct |
98 ms |
31396 KB |
Output is correct |
45 |
Correct |
81 ms |
30284 KB |
Output is correct |
46 |
Correct |
47 ms |
37360 KB |
Output is correct |
47 |
Correct |
160 ms |
44976 KB |
Output is correct |
48 |
Correct |
231 ms |
79660 KB |
Output is correct |
49 |
Correct |
225 ms |
77960 KB |
Output is correct |
50 |
Correct |
139 ms |
45004 KB |
Output is correct |
51 |
Correct |
140 ms |
44912 KB |
Output is correct |
52 |
Correct |
182 ms |
45144 KB |
Output is correct |
53 |
Correct |
211 ms |
48448 KB |
Output is correct |
54 |
Correct |
268 ms |
73288 KB |
Output is correct |
55 |
Correct |
12 ms |
5724 KB |
Output is correct |
56 |
Correct |
6 ms |
4700 KB |
Output is correct |
57 |
Correct |
51 ms |
27220 KB |
Output is correct |
58 |
Correct |
45 ms |
22340 KB |
Output is correct |
59 |
Correct |
71 ms |
41808 KB |
Output is correct |
60 |
Correct |
218 ms |
78420 KB |
Output is correct |
61 |
Correct |
168 ms |
47700 KB |
Output is correct |
62 |
Correct |
141 ms |
44968 KB |
Output is correct |
63 |
Correct |
219 ms |
45140 KB |
Output is correct |
64 |
Correct |
363 ms |
86704 KB |
Output is correct |
65 |
Correct |
364 ms |
85428 KB |
Output is correct |
66 |
Correct |
231 ms |
74564 KB |
Output is correct |
67 |
Correct |
130 ms |
41132 KB |
Output is correct |
68 |
Correct |
313 ms |
57884 KB |
Output is correct |
69 |
Correct |
287 ms |
61864 KB |
Output is correct |
70 |
Correct |
256 ms |
55628 KB |
Output is correct |