# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
551472 |
2022-04-20T19:19:18 Z |
Leo121 |
Race (IOI11_race) |
C++14 |
|
401 ms |
92848 KB |
#include <bits/stdc++.h>
#include "race.h"
#define forn(i, a, b) for(int i = int(a); i <= int(b); ++ i)
#define fora(i, a, b) for(int i = int(a); i >= int(b); -- i)
#define foru(i, v) for(auto i : v)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int maxn = 2e5;
map<ll, int> *cnt[maxn];
int sz[maxn];
int prof[maxn];
ll tam[maxn];
vpii tree[maxn];
int res, k;
void dfs(int u, int p){
int mx = -1, bigchild = -1;
sz[u] = 1;
foru(v, tree[u]){
if(v.fi != p){
prof[v.fi] = prof[u] + 1;
tam[v.fi] = tam[u] + (ll) v.se;
dfs(v.fi, u);
sz[u] += sz[v.fi];
if(sz[v.fi] > mx){
mx = sz[v.fi];
bigchild = v.fi;
}
}
}
cnt[u] = (bigchild == -1) ? new map<ll, int> : cnt[bigchild];
ll distancia;
foru(v, tree[u]){
if(v.fi != p && v.fi != bigchild){
foru(i, *cnt[v.fi]){
distancia = i.fi;
distancia -= tam[u];
if((*cnt[u]).count(tam[u] + ((ll) k - distancia))){
res = (res == -1) ? ((*cnt[u])[tam[u] + ((ll) k - distancia)] - prof[u]) + (i.se - prof[u]) : min(res, ((*cnt[u])[tam[u] + ((ll) k - distancia)] - prof[u]) + (i.se - prof[u]));
}
}
foru(i, *cnt[v.fi]){
if((*cnt[u]).count(i.first)){
(*cnt[u])[i.first] = min((*cnt[u])[i.first], i.second);
continue;
}
(*cnt[u])[i.first] = i.second;
}
}
}
if((*cnt[u]).count((ll) k + tam[u])){
res = (res == -1) ? ((*cnt[u])[tam[u] + (ll) k] - prof[u]) : min(res, ((*cnt[u])[tam[u] + (ll) k] - prof[u]));
}
(*cnt[u])[tam[u]] = prof[u];
}
int best_path(int N, int K, int H[][2], int L[]){
forn(i, 0, N - 2){
tree[H[i][0]].pb(mp(H[i][1], L[i]));
tree[H[i][1]].pb(mp(H[i][0], L[i]));
}
k = K;
res = -1;
dfs(0, 0);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4976 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5024 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
5016 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5020 KB |
Output is correct |
12 |
Correct |
4 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4976 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5024 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
5016 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5020 KB |
Output is correct |
12 |
Correct |
4 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5020 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
5204 KB |
Output is correct |
22 |
Correct |
4 ms |
5332 KB |
Output is correct |
23 |
Correct |
4 ms |
5332 KB |
Output is correct |
24 |
Correct |
4 ms |
5284 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
4 ms |
5332 KB |
Output is correct |
27 |
Correct |
4 ms |
5156 KB |
Output is correct |
28 |
Correct |
4 ms |
5332 KB |
Output is correct |
29 |
Correct |
4 ms |
5356 KB |
Output is correct |
30 |
Correct |
4 ms |
5332 KB |
Output is correct |
31 |
Correct |
4 ms |
5288 KB |
Output is correct |
32 |
Correct |
4 ms |
5332 KB |
Output is correct |
33 |
Correct |
4 ms |
5292 KB |
Output is correct |
34 |
Correct |
3 ms |
5204 KB |
Output is correct |
35 |
Correct |
4 ms |
5156 KB |
Output is correct |
36 |
Correct |
3 ms |
5204 KB |
Output is correct |
37 |
Correct |
4 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4976 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5024 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
5016 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5020 KB |
Output is correct |
12 |
Correct |
4 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5020 KB |
Output is correct |
19 |
Correct |
106 ms |
27284 KB |
Output is correct |
20 |
Correct |
102 ms |
27200 KB |
Output is correct |
21 |
Correct |
103 ms |
27328 KB |
Output is correct |
22 |
Correct |
111 ms |
27904 KB |
Output is correct |
23 |
Correct |
140 ms |
41520 KB |
Output is correct |
24 |
Correct |
112 ms |
36400 KB |
Output is correct |
25 |
Correct |
72 ms |
24396 KB |
Output is correct |
26 |
Correct |
51 ms |
33328 KB |
Output is correct |
27 |
Correct |
190 ms |
41676 KB |
Output is correct |
28 |
Correct |
231 ms |
74448 KB |
Output is correct |
29 |
Correct |
253 ms |
72432 KB |
Output is correct |
30 |
Correct |
183 ms |
41592 KB |
Output is correct |
31 |
Correct |
183 ms |
41588 KB |
Output is correct |
32 |
Correct |
218 ms |
41648 KB |
Output is correct |
33 |
Correct |
188 ms |
34460 KB |
Output is correct |
34 |
Correct |
264 ms |
67168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4976 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5024 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
5016 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
5020 KB |
Output is correct |
12 |
Correct |
4 ms |
5024 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5020 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
5204 KB |
Output is correct |
22 |
Correct |
4 ms |
5332 KB |
Output is correct |
23 |
Correct |
4 ms |
5332 KB |
Output is correct |
24 |
Correct |
4 ms |
5284 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
4 ms |
5332 KB |
Output is correct |
27 |
Correct |
4 ms |
5156 KB |
Output is correct |
28 |
Correct |
4 ms |
5332 KB |
Output is correct |
29 |
Correct |
4 ms |
5356 KB |
Output is correct |
30 |
Correct |
4 ms |
5332 KB |
Output is correct |
31 |
Correct |
4 ms |
5288 KB |
Output is correct |
32 |
Correct |
4 ms |
5332 KB |
Output is correct |
33 |
Correct |
4 ms |
5292 KB |
Output is correct |
34 |
Correct |
3 ms |
5204 KB |
Output is correct |
35 |
Correct |
4 ms |
5156 KB |
Output is correct |
36 |
Correct |
3 ms |
5204 KB |
Output is correct |
37 |
Correct |
4 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5204 KB |
Output is correct |
39 |
Correct |
106 ms |
27284 KB |
Output is correct |
40 |
Correct |
102 ms |
27200 KB |
Output is correct |
41 |
Correct |
103 ms |
27328 KB |
Output is correct |
42 |
Correct |
111 ms |
27904 KB |
Output is correct |
43 |
Correct |
140 ms |
41520 KB |
Output is correct |
44 |
Correct |
112 ms |
36400 KB |
Output is correct |
45 |
Correct |
72 ms |
24396 KB |
Output is correct |
46 |
Correct |
51 ms |
33328 KB |
Output is correct |
47 |
Correct |
190 ms |
41676 KB |
Output is correct |
48 |
Correct |
231 ms |
74448 KB |
Output is correct |
49 |
Correct |
253 ms |
72432 KB |
Output is correct |
50 |
Correct |
183 ms |
41592 KB |
Output is correct |
51 |
Correct |
183 ms |
41588 KB |
Output is correct |
52 |
Correct |
218 ms |
41648 KB |
Output is correct |
53 |
Correct |
188 ms |
34460 KB |
Output is correct |
54 |
Correct |
264 ms |
67168 KB |
Output is correct |
55 |
Correct |
15 ms |
8292 KB |
Output is correct |
56 |
Correct |
10 ms |
6844 KB |
Output is correct |
57 |
Correct |
75 ms |
26572 KB |
Output is correct |
58 |
Correct |
56 ms |
26000 KB |
Output is correct |
59 |
Correct |
69 ms |
39564 KB |
Output is correct |
60 |
Correct |
213 ms |
72936 KB |
Output is correct |
61 |
Correct |
247 ms |
45208 KB |
Output is correct |
62 |
Correct |
155 ms |
41604 KB |
Output is correct |
63 |
Correct |
220 ms |
41656 KB |
Output is correct |
64 |
Correct |
401 ms |
91168 KB |
Output is correct |
65 |
Correct |
392 ms |
92848 KB |
Output is correct |
66 |
Correct |
215 ms |
67792 KB |
Output is correct |
67 |
Correct |
157 ms |
48056 KB |
Output is correct |
68 |
Correct |
287 ms |
62168 KB |
Output is correct |
69 |
Correct |
292 ms |
63148 KB |
Output is correct |
70 |
Correct |
291 ms |
59908 KB |
Output is correct |