# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871618 |
2023-11-11T07:53:24 Z |
dsyz |
Race (IOI11_race) |
C++17 |
|
395 ms |
111396 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
using ll = long long;
#define MAXN (200005)
ll n,k;
ll ans = 1e18;
vector<pair<ll,ll> > v[MAXN];
map<ll,ll> m[MAXN];
pair<ll,ll> offset[MAXN];
void dfs(ll x,ll p){
m[x][0] = 0;
for(auto u : v[x]){
if(u.first != p){
dfs(u.first,x);
offset[u.first].first += u.second;
offset[u.first].second++;
if(m[u.first].size() > m[x].size()){
swap(m[u.first],m[x]);
swap(offset[u.first],offset[x]);
}
for(auto a : m[u.first]){
ll t = k - a.first - offset[x].first - offset[u.first].first;
if(m[x].count(t)) ans = min(ans,m[x][t] + offset[x].second + a.second + offset[u.first].second);
}
for(auto a : m[u.first]){
ll t = a.first + offset[u.first].first - offset[x].first;
if(m[x].count(t)) m[x][t] = min(m[x][t],a.second + offset[u.first].second - offset[x].second);
else m[x][t] = a.second + offset[u.first].second - offset[x].second;
}
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
n = N;
k = K;
for(ll i = 0;i < N - 1;i++){
ll a = H[i][0];
ll b = H[i][1];
ll c = L[i];
v[a].push_back({b,c});
v[b].push_back({a,c});
}
dfs(0,-1);
if(ans == 1e18) return -1;
else return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
19036 KB |
Output is correct |
2 |
Correct |
4 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19292 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
4 ms |
19036 KB |
Output is correct |
6 |
Correct |
4 ms |
19292 KB |
Output is correct |
7 |
Correct |
4 ms |
19036 KB |
Output is correct |
8 |
Correct |
4 ms |
19288 KB |
Output is correct |
9 |
Correct |
4 ms |
19236 KB |
Output is correct |
10 |
Correct |
4 ms |
19292 KB |
Output is correct |
11 |
Correct |
4 ms |
19036 KB |
Output is correct |
12 |
Correct |
5 ms |
19036 KB |
Output is correct |
13 |
Correct |
4 ms |
19124 KB |
Output is correct |
14 |
Correct |
4 ms |
19292 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
4 ms |
19036 KB |
Output is correct |
17 |
Correct |
4 ms |
19292 KB |
Output is correct |
18 |
Correct |
4 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
19036 KB |
Output is correct |
2 |
Correct |
4 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19292 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
4 ms |
19036 KB |
Output is correct |
6 |
Correct |
4 ms |
19292 KB |
Output is correct |
7 |
Correct |
4 ms |
19036 KB |
Output is correct |
8 |
Correct |
4 ms |
19288 KB |
Output is correct |
9 |
Correct |
4 ms |
19236 KB |
Output is correct |
10 |
Correct |
4 ms |
19292 KB |
Output is correct |
11 |
Correct |
4 ms |
19036 KB |
Output is correct |
12 |
Correct |
5 ms |
19036 KB |
Output is correct |
13 |
Correct |
4 ms |
19124 KB |
Output is correct |
14 |
Correct |
4 ms |
19292 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
4 ms |
19036 KB |
Output is correct |
17 |
Correct |
4 ms |
19292 KB |
Output is correct |
18 |
Correct |
4 ms |
19036 KB |
Output is correct |
19 |
Correct |
3 ms |
19036 KB |
Output is correct |
20 |
Correct |
4 ms |
19036 KB |
Output is correct |
21 |
Correct |
4 ms |
19288 KB |
Output is correct |
22 |
Correct |
5 ms |
19540 KB |
Output is correct |
23 |
Correct |
5 ms |
19548 KB |
Output is correct |
24 |
Correct |
5 ms |
19548 KB |
Output is correct |
25 |
Correct |
5 ms |
19548 KB |
Output is correct |
26 |
Correct |
5 ms |
19548 KB |
Output is correct |
27 |
Correct |
5 ms |
19292 KB |
Output is correct |
28 |
Correct |
5 ms |
19548 KB |
Output is correct |
29 |
Correct |
4 ms |
19544 KB |
Output is correct |
30 |
Correct |
5 ms |
19548 KB |
Output is correct |
31 |
Correct |
5 ms |
19548 KB |
Output is correct |
32 |
Correct |
5 ms |
19372 KB |
Output is correct |
33 |
Correct |
5 ms |
19548 KB |
Output is correct |
34 |
Correct |
5 ms |
19292 KB |
Output is correct |
35 |
Correct |
5 ms |
19292 KB |
Output is correct |
36 |
Correct |
4 ms |
19292 KB |
Output is correct |
37 |
Correct |
4 ms |
19252 KB |
Output is correct |
38 |
Correct |
5 ms |
19292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
19036 KB |
Output is correct |
2 |
Correct |
4 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19292 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
4 ms |
19036 KB |
Output is correct |
6 |
Correct |
4 ms |
19292 KB |
Output is correct |
7 |
Correct |
4 ms |
19036 KB |
Output is correct |
8 |
Correct |
4 ms |
19288 KB |
Output is correct |
9 |
Correct |
4 ms |
19236 KB |
Output is correct |
10 |
Correct |
4 ms |
19292 KB |
Output is correct |
11 |
Correct |
4 ms |
19036 KB |
Output is correct |
12 |
Correct |
5 ms |
19036 KB |
Output is correct |
13 |
Correct |
4 ms |
19124 KB |
Output is correct |
14 |
Correct |
4 ms |
19292 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
4 ms |
19036 KB |
Output is correct |
17 |
Correct |
4 ms |
19292 KB |
Output is correct |
18 |
Correct |
4 ms |
19036 KB |
Output is correct |
19 |
Correct |
127 ms |
45592 KB |
Output is correct |
20 |
Correct |
98 ms |
45336 KB |
Output is correct |
21 |
Correct |
91 ms |
45232 KB |
Output is correct |
22 |
Correct |
114 ms |
44732 KB |
Output is correct |
23 |
Correct |
138 ms |
56716 KB |
Output is correct |
24 |
Correct |
106 ms |
47648 KB |
Output is correct |
25 |
Correct |
95 ms |
45340 KB |
Output is correct |
26 |
Correct |
53 ms |
52988 KB |
Output is correct |
27 |
Correct |
153 ms |
56136 KB |
Output is correct |
28 |
Correct |
234 ms |
95160 KB |
Output is correct |
29 |
Correct |
249 ms |
93844 KB |
Output is correct |
30 |
Correct |
155 ms |
56148 KB |
Output is correct |
31 |
Correct |
153 ms |
56144 KB |
Output is correct |
32 |
Correct |
213 ms |
56404 KB |
Output is correct |
33 |
Correct |
195 ms |
61008 KB |
Output is correct |
34 |
Correct |
316 ms |
94012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
19036 KB |
Output is correct |
2 |
Correct |
4 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19292 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
4 ms |
19036 KB |
Output is correct |
6 |
Correct |
4 ms |
19292 KB |
Output is correct |
7 |
Correct |
4 ms |
19036 KB |
Output is correct |
8 |
Correct |
4 ms |
19288 KB |
Output is correct |
9 |
Correct |
4 ms |
19236 KB |
Output is correct |
10 |
Correct |
4 ms |
19292 KB |
Output is correct |
11 |
Correct |
4 ms |
19036 KB |
Output is correct |
12 |
Correct |
5 ms |
19036 KB |
Output is correct |
13 |
Correct |
4 ms |
19124 KB |
Output is correct |
14 |
Correct |
4 ms |
19292 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
4 ms |
19036 KB |
Output is correct |
17 |
Correct |
4 ms |
19292 KB |
Output is correct |
18 |
Correct |
4 ms |
19036 KB |
Output is correct |
19 |
Correct |
3 ms |
19036 KB |
Output is correct |
20 |
Correct |
4 ms |
19036 KB |
Output is correct |
21 |
Correct |
4 ms |
19288 KB |
Output is correct |
22 |
Correct |
5 ms |
19540 KB |
Output is correct |
23 |
Correct |
5 ms |
19548 KB |
Output is correct |
24 |
Correct |
5 ms |
19548 KB |
Output is correct |
25 |
Correct |
5 ms |
19548 KB |
Output is correct |
26 |
Correct |
5 ms |
19548 KB |
Output is correct |
27 |
Correct |
5 ms |
19292 KB |
Output is correct |
28 |
Correct |
5 ms |
19548 KB |
Output is correct |
29 |
Correct |
4 ms |
19544 KB |
Output is correct |
30 |
Correct |
5 ms |
19548 KB |
Output is correct |
31 |
Correct |
5 ms |
19548 KB |
Output is correct |
32 |
Correct |
5 ms |
19372 KB |
Output is correct |
33 |
Correct |
5 ms |
19548 KB |
Output is correct |
34 |
Correct |
5 ms |
19292 KB |
Output is correct |
35 |
Correct |
5 ms |
19292 KB |
Output is correct |
36 |
Correct |
4 ms |
19292 KB |
Output is correct |
37 |
Correct |
4 ms |
19252 KB |
Output is correct |
38 |
Correct |
5 ms |
19292 KB |
Output is correct |
39 |
Correct |
127 ms |
45592 KB |
Output is correct |
40 |
Correct |
98 ms |
45336 KB |
Output is correct |
41 |
Correct |
91 ms |
45232 KB |
Output is correct |
42 |
Correct |
114 ms |
44732 KB |
Output is correct |
43 |
Correct |
138 ms |
56716 KB |
Output is correct |
44 |
Correct |
106 ms |
47648 KB |
Output is correct |
45 |
Correct |
95 ms |
45340 KB |
Output is correct |
46 |
Correct |
53 ms |
52988 KB |
Output is correct |
47 |
Correct |
153 ms |
56136 KB |
Output is correct |
48 |
Correct |
234 ms |
95160 KB |
Output is correct |
49 |
Correct |
249 ms |
93844 KB |
Output is correct |
50 |
Correct |
155 ms |
56148 KB |
Output is correct |
51 |
Correct |
153 ms |
56144 KB |
Output is correct |
52 |
Correct |
213 ms |
56404 KB |
Output is correct |
53 |
Correct |
195 ms |
61008 KB |
Output is correct |
54 |
Correct |
316 ms |
94012 KB |
Output is correct |
55 |
Correct |
15 ms |
22360 KB |
Output is correct |
56 |
Correct |
10 ms |
20928 KB |
Output is correct |
57 |
Correct |
60 ms |
42840 KB |
Output is correct |
58 |
Correct |
43 ms |
35316 KB |
Output is correct |
59 |
Correct |
74 ms |
59216 KB |
Output is correct |
60 |
Correct |
222 ms |
94032 KB |
Output is correct |
61 |
Correct |
180 ms |
59680 KB |
Output is correct |
62 |
Correct |
160 ms |
56232 KB |
Output is correct |
63 |
Correct |
210 ms |
56252 KB |
Output is correct |
64 |
Correct |
395 ms |
111396 KB |
Output is correct |
65 |
Correct |
370 ms |
109180 KB |
Output is correct |
66 |
Correct |
245 ms |
90268 KB |
Output is correct |
67 |
Correct |
149 ms |
48932 KB |
Output is correct |
68 |
Correct |
299 ms |
72792 KB |
Output is correct |
69 |
Correct |
351 ms |
77396 KB |
Output is correct |
70 |
Correct |
288 ms |
70484 KB |
Output is correct |