# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
866045 |
2023-10-25T10:37:46 Z |
dpsaveslives |
Race (IOI11_race) |
C++17 |
|
419 ms |
111220 KB |
#include "race.h"
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
const int MAXN = 2e5+10;
vector<pair<ll,ll>> adj[MAXN];
map<ll,ll> help[MAXN];
ll dep[MAXN], dist[MAXN],ans;
int k,n;
void dfs(int u, int p, int de, ll di){
dep[u] = de; dist[u] = di;
help[u][di] = de;
for(auto pa : adj[u]){
if(pa.f != p){
dfs(pa.f,u,dep[u]+1,dist[u]+pa.s);
}
}
}
void comb(int u, int p){
int tar = k+2*dist[u];
for(auto pa : adj[u]){
int v = pa.f;
if(v != p){
comb(v,u);
if(help[v].size() > help[u].size()) swap(help[v],help[u]);
for(auto x : help[v]){
if(help[u].find(tar-x.f) != help[u].end()){
ans = min(ans,help[u][tar-x.f]+x.s-2*dep[u]);
}
}
for(auto x : help[v]){
if(help[u].find(x.f) != help[u].end()){
help[u][x.f] = min(help[u][x.f],x.s);
}
else{
help[u].insert(x);
}
}
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
for(int i = 0;i<N-1;++i){
int u = H[i][0], v = H[i][1], w = L[i];
adj[u].push_back({v,w}); adj[v].push_back({u,w});
}
dfs(0,-1,0,0);
n = N; k = K; ans = INT_MAX;
comb(0,-1);
if(ans != INT_MAX) return ans;
else return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
4 ms |
21340 KB |
Output is correct |
3 |
Correct |
4 ms |
21296 KB |
Output is correct |
4 |
Correct |
5 ms |
21288 KB |
Output is correct |
5 |
Correct |
4 ms |
21340 KB |
Output is correct |
6 |
Correct |
5 ms |
21308 KB |
Output is correct |
7 |
Correct |
4 ms |
21272 KB |
Output is correct |
8 |
Correct |
4 ms |
21336 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
21592 KB |
Output is correct |
11 |
Correct |
4 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21272 KB |
Output is correct |
13 |
Correct |
4 ms |
21340 KB |
Output is correct |
14 |
Correct |
4 ms |
21340 KB |
Output is correct |
15 |
Correct |
4 ms |
21296 KB |
Output is correct |
16 |
Correct |
4 ms |
21592 KB |
Output is correct |
17 |
Correct |
4 ms |
21272 KB |
Output is correct |
18 |
Correct |
4 ms |
21340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
4 ms |
21340 KB |
Output is correct |
3 |
Correct |
4 ms |
21296 KB |
Output is correct |
4 |
Correct |
5 ms |
21288 KB |
Output is correct |
5 |
Correct |
4 ms |
21340 KB |
Output is correct |
6 |
Correct |
5 ms |
21308 KB |
Output is correct |
7 |
Correct |
4 ms |
21272 KB |
Output is correct |
8 |
Correct |
4 ms |
21336 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
21592 KB |
Output is correct |
11 |
Correct |
4 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21272 KB |
Output is correct |
13 |
Correct |
4 ms |
21340 KB |
Output is correct |
14 |
Correct |
4 ms |
21340 KB |
Output is correct |
15 |
Correct |
4 ms |
21296 KB |
Output is correct |
16 |
Correct |
4 ms |
21592 KB |
Output is correct |
17 |
Correct |
4 ms |
21272 KB |
Output is correct |
18 |
Correct |
4 ms |
21340 KB |
Output is correct |
19 |
Correct |
4 ms |
21080 KB |
Output is correct |
20 |
Correct |
4 ms |
21292 KB |
Output is correct |
21 |
Correct |
5 ms |
21336 KB |
Output is correct |
22 |
Correct |
5 ms |
21568 KB |
Output is correct |
23 |
Correct |
5 ms |
21596 KB |
Output is correct |
24 |
Correct |
5 ms |
21596 KB |
Output is correct |
25 |
Correct |
5 ms |
21592 KB |
Output is correct |
26 |
Correct |
6 ms |
21848 KB |
Output is correct |
27 |
Correct |
4 ms |
21280 KB |
Output is correct |
28 |
Correct |
5 ms |
21604 KB |
Output is correct |
29 |
Correct |
5 ms |
21612 KB |
Output is correct |
30 |
Correct |
6 ms |
21596 KB |
Output is correct |
31 |
Correct |
5 ms |
21596 KB |
Output is correct |
32 |
Correct |
5 ms |
21388 KB |
Output is correct |
33 |
Correct |
5 ms |
21592 KB |
Output is correct |
34 |
Correct |
4 ms |
21340 KB |
Output is correct |
35 |
Correct |
4 ms |
21340 KB |
Output is correct |
36 |
Correct |
4 ms |
21340 KB |
Output is correct |
37 |
Correct |
4 ms |
21304 KB |
Output is correct |
38 |
Correct |
5 ms |
21340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
4 ms |
21340 KB |
Output is correct |
3 |
Correct |
4 ms |
21296 KB |
Output is correct |
4 |
Correct |
5 ms |
21288 KB |
Output is correct |
5 |
Correct |
4 ms |
21340 KB |
Output is correct |
6 |
Correct |
5 ms |
21308 KB |
Output is correct |
7 |
Correct |
4 ms |
21272 KB |
Output is correct |
8 |
Correct |
4 ms |
21336 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
21592 KB |
Output is correct |
11 |
Correct |
4 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21272 KB |
Output is correct |
13 |
Correct |
4 ms |
21340 KB |
Output is correct |
14 |
Correct |
4 ms |
21340 KB |
Output is correct |
15 |
Correct |
4 ms |
21296 KB |
Output is correct |
16 |
Correct |
4 ms |
21592 KB |
Output is correct |
17 |
Correct |
4 ms |
21272 KB |
Output is correct |
18 |
Correct |
4 ms |
21340 KB |
Output is correct |
19 |
Correct |
132 ms |
45396 KB |
Output is correct |
20 |
Correct |
124 ms |
45552 KB |
Output is correct |
21 |
Correct |
112 ms |
45216 KB |
Output is correct |
22 |
Correct |
107 ms |
44848 KB |
Output is correct |
23 |
Correct |
144 ms |
57684 KB |
Output is correct |
24 |
Correct |
109 ms |
47952 KB |
Output is correct |
25 |
Correct |
94 ms |
46160 KB |
Output is correct |
26 |
Correct |
53 ms |
54472 KB |
Output is correct |
27 |
Correct |
166 ms |
56144 KB |
Output is correct |
28 |
Correct |
250 ms |
98384 KB |
Output is correct |
29 |
Correct |
252 ms |
96612 KB |
Output is correct |
30 |
Correct |
166 ms |
56132 KB |
Output is correct |
31 |
Correct |
176 ms |
56144 KB |
Output is correct |
32 |
Correct |
240 ms |
56400 KB |
Output is correct |
33 |
Correct |
262 ms |
61192 KB |
Output is correct |
34 |
Correct |
308 ms |
94032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
4 ms |
21340 KB |
Output is correct |
3 |
Correct |
4 ms |
21296 KB |
Output is correct |
4 |
Correct |
5 ms |
21288 KB |
Output is correct |
5 |
Correct |
4 ms |
21340 KB |
Output is correct |
6 |
Correct |
5 ms |
21308 KB |
Output is correct |
7 |
Correct |
4 ms |
21272 KB |
Output is correct |
8 |
Correct |
4 ms |
21336 KB |
Output is correct |
9 |
Correct |
4 ms |
21080 KB |
Output is correct |
10 |
Correct |
4 ms |
21592 KB |
Output is correct |
11 |
Correct |
4 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21272 KB |
Output is correct |
13 |
Correct |
4 ms |
21340 KB |
Output is correct |
14 |
Correct |
4 ms |
21340 KB |
Output is correct |
15 |
Correct |
4 ms |
21296 KB |
Output is correct |
16 |
Correct |
4 ms |
21592 KB |
Output is correct |
17 |
Correct |
4 ms |
21272 KB |
Output is correct |
18 |
Correct |
4 ms |
21340 KB |
Output is correct |
19 |
Correct |
4 ms |
21080 KB |
Output is correct |
20 |
Correct |
4 ms |
21292 KB |
Output is correct |
21 |
Correct |
5 ms |
21336 KB |
Output is correct |
22 |
Correct |
5 ms |
21568 KB |
Output is correct |
23 |
Correct |
5 ms |
21596 KB |
Output is correct |
24 |
Correct |
5 ms |
21596 KB |
Output is correct |
25 |
Correct |
5 ms |
21592 KB |
Output is correct |
26 |
Correct |
6 ms |
21848 KB |
Output is correct |
27 |
Correct |
4 ms |
21280 KB |
Output is correct |
28 |
Correct |
5 ms |
21604 KB |
Output is correct |
29 |
Correct |
5 ms |
21612 KB |
Output is correct |
30 |
Correct |
6 ms |
21596 KB |
Output is correct |
31 |
Correct |
5 ms |
21596 KB |
Output is correct |
32 |
Correct |
5 ms |
21388 KB |
Output is correct |
33 |
Correct |
5 ms |
21592 KB |
Output is correct |
34 |
Correct |
4 ms |
21340 KB |
Output is correct |
35 |
Correct |
4 ms |
21340 KB |
Output is correct |
36 |
Correct |
4 ms |
21340 KB |
Output is correct |
37 |
Correct |
4 ms |
21304 KB |
Output is correct |
38 |
Correct |
5 ms |
21340 KB |
Output is correct |
39 |
Correct |
132 ms |
45396 KB |
Output is correct |
40 |
Correct |
124 ms |
45552 KB |
Output is correct |
41 |
Correct |
112 ms |
45216 KB |
Output is correct |
42 |
Correct |
107 ms |
44848 KB |
Output is correct |
43 |
Correct |
144 ms |
57684 KB |
Output is correct |
44 |
Correct |
109 ms |
47952 KB |
Output is correct |
45 |
Correct |
94 ms |
46160 KB |
Output is correct |
46 |
Correct |
53 ms |
54472 KB |
Output is correct |
47 |
Correct |
166 ms |
56144 KB |
Output is correct |
48 |
Correct |
250 ms |
98384 KB |
Output is correct |
49 |
Correct |
252 ms |
96612 KB |
Output is correct |
50 |
Correct |
166 ms |
56132 KB |
Output is correct |
51 |
Correct |
176 ms |
56144 KB |
Output is correct |
52 |
Correct |
240 ms |
56400 KB |
Output is correct |
53 |
Correct |
262 ms |
61192 KB |
Output is correct |
54 |
Correct |
308 ms |
94032 KB |
Output is correct |
55 |
Correct |
16 ms |
24452 KB |
Output is correct |
56 |
Correct |
11 ms |
23220 KB |
Output is correct |
57 |
Correct |
63 ms |
43448 KB |
Output is correct |
58 |
Correct |
43 ms |
35520 KB |
Output is correct |
59 |
Correct |
77 ms |
60716 KB |
Output is correct |
60 |
Correct |
239 ms |
97104 KB |
Output is correct |
61 |
Correct |
205 ms |
59876 KB |
Output is correct |
62 |
Correct |
164 ms |
56136 KB |
Output is correct |
63 |
Correct |
244 ms |
56256 KB |
Output is correct |
64 |
Correct |
419 ms |
111220 KB |
Output is correct |
65 |
Correct |
384 ms |
109116 KB |
Output is correct |
66 |
Correct |
266 ms |
92496 KB |
Output is correct |
67 |
Correct |
145 ms |
49844 KB |
Output is correct |
68 |
Correct |
331 ms |
72996 KB |
Output is correct |
69 |
Correct |
330 ms |
77396 KB |
Output is correct |
70 |
Correct |
297 ms |
70860 KB |
Output is correct |