# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
788711 |
2023-07-20T14:08:52 Z |
vjudge1 |
Race (IOI11_race) |
C++17 |
|
428 ms |
104700 KB |
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ii pair<int,int>
const int ms = 2e5 + 10;
ll h[ms], dis[ms], ans, k, n;
vector<ii> g[ms];
map<ll, ll > mp[ms];
void dfs(int u=0, int p=-1, ll d=0, int height =0){
mp[u][d]= height;
h[u] = height;
dis[u] = d;
for(auto [v, w] : g[u]){
if(v == p) continue;
dfs(v, u, d+w, height+1);
}
}
void sack(int u=0, int p=-1){
// dis[u] + target = k
// x + y - (2 * dis[u]) = k
// x + y = 2*dis[u] + k
// y = 2*dis[u] + k - x
for(auto [v, w] : g[u]){
if(v == p) continue;
sack(v, u);
if(mp[v].size() > mp[u].size()) mp[u].swap(mp[v]);
for(auto [x, y] : mp[v]){
if(mp[u].find(2ll*dis[u] + k - x) != mp[u].end()){
ll now = y + mp[u][2*dis[u] + k - x] - 2*h[u];
if(ans == -1 || ans > now) ans = now;
}
}
for(auto [x, y] : mp[v]){
if(mp[u].find(x) != mp[u].end()){
mp[u][x] = min(mp[u][x], y);
}
else mp[u][x] = y;
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
k = K;
n = N;
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]});
}
ans = -1;
dfs();
sack();
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14404 KB |
Output is correct |
3 |
Correct |
7 ms |
14408 KB |
Output is correct |
4 |
Correct |
7 ms |
14408 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
6 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14408 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
7 ms |
14456 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
6 ms |
14420 KB |
Output is correct |
12 |
Correct |
6 ms |
14332 KB |
Output is correct |
13 |
Correct |
7 ms |
14380 KB |
Output is correct |
14 |
Correct |
6 ms |
14420 KB |
Output is correct |
15 |
Correct |
6 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14340 KB |
Output is correct |
17 |
Correct |
7 ms |
14420 KB |
Output is correct |
18 |
Correct |
7 ms |
14420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14404 KB |
Output is correct |
3 |
Correct |
7 ms |
14408 KB |
Output is correct |
4 |
Correct |
7 ms |
14408 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
6 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14408 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
7 ms |
14456 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
6 ms |
14420 KB |
Output is correct |
12 |
Correct |
6 ms |
14332 KB |
Output is correct |
13 |
Correct |
7 ms |
14380 KB |
Output is correct |
14 |
Correct |
6 ms |
14420 KB |
Output is correct |
15 |
Correct |
6 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14340 KB |
Output is correct |
17 |
Correct |
7 ms |
14420 KB |
Output is correct |
18 |
Correct |
7 ms |
14420 KB |
Output is correct |
19 |
Correct |
7 ms |
14404 KB |
Output is correct |
20 |
Correct |
7 ms |
14420 KB |
Output is correct |
21 |
Correct |
7 ms |
14676 KB |
Output is correct |
22 |
Correct |
8 ms |
14644 KB |
Output is correct |
23 |
Correct |
7 ms |
14676 KB |
Output is correct |
24 |
Correct |
7 ms |
14676 KB |
Output is correct |
25 |
Correct |
7 ms |
14676 KB |
Output is correct |
26 |
Correct |
7 ms |
14672 KB |
Output is correct |
27 |
Correct |
7 ms |
14548 KB |
Output is correct |
28 |
Correct |
8 ms |
14676 KB |
Output is correct |
29 |
Correct |
8 ms |
14676 KB |
Output is correct |
30 |
Correct |
8 ms |
14620 KB |
Output is correct |
31 |
Correct |
8 ms |
14676 KB |
Output is correct |
32 |
Correct |
8 ms |
14676 KB |
Output is correct |
33 |
Correct |
9 ms |
14676 KB |
Output is correct |
34 |
Correct |
8 ms |
14676 KB |
Output is correct |
35 |
Correct |
7 ms |
14676 KB |
Output is correct |
36 |
Correct |
7 ms |
14676 KB |
Output is correct |
37 |
Correct |
8 ms |
14548 KB |
Output is correct |
38 |
Correct |
8 ms |
14672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14404 KB |
Output is correct |
3 |
Correct |
7 ms |
14408 KB |
Output is correct |
4 |
Correct |
7 ms |
14408 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
6 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14408 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
7 ms |
14456 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
6 ms |
14420 KB |
Output is correct |
12 |
Correct |
6 ms |
14332 KB |
Output is correct |
13 |
Correct |
7 ms |
14380 KB |
Output is correct |
14 |
Correct |
6 ms |
14420 KB |
Output is correct |
15 |
Correct |
6 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14340 KB |
Output is correct |
17 |
Correct |
7 ms |
14420 KB |
Output is correct |
18 |
Correct |
7 ms |
14420 KB |
Output is correct |
19 |
Correct |
106 ms |
37692 KB |
Output is correct |
20 |
Correct |
140 ms |
37688 KB |
Output is correct |
21 |
Correct |
117 ms |
37472 KB |
Output is correct |
22 |
Correct |
133 ms |
37168 KB |
Output is correct |
23 |
Correct |
150 ms |
49832 KB |
Output is correct |
24 |
Correct |
109 ms |
40484 KB |
Output is correct |
25 |
Correct |
95 ms |
38336 KB |
Output is correct |
26 |
Correct |
56 ms |
46652 KB |
Output is correct |
27 |
Correct |
166 ms |
49356 KB |
Output is correct |
28 |
Correct |
283 ms |
91732 KB |
Output is correct |
29 |
Correct |
285 ms |
89828 KB |
Output is correct |
30 |
Correct |
160 ms |
49444 KB |
Output is correct |
31 |
Correct |
165 ms |
49444 KB |
Output is correct |
32 |
Correct |
239 ms |
49540 KB |
Output is correct |
33 |
Correct |
241 ms |
54536 KB |
Output is correct |
34 |
Correct |
321 ms |
87312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14404 KB |
Output is correct |
3 |
Correct |
7 ms |
14408 KB |
Output is correct |
4 |
Correct |
7 ms |
14408 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
6 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14408 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
7 ms |
14456 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
6 ms |
14420 KB |
Output is correct |
12 |
Correct |
6 ms |
14332 KB |
Output is correct |
13 |
Correct |
7 ms |
14380 KB |
Output is correct |
14 |
Correct |
6 ms |
14420 KB |
Output is correct |
15 |
Correct |
6 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14340 KB |
Output is correct |
17 |
Correct |
7 ms |
14420 KB |
Output is correct |
18 |
Correct |
7 ms |
14420 KB |
Output is correct |
19 |
Correct |
7 ms |
14404 KB |
Output is correct |
20 |
Correct |
7 ms |
14420 KB |
Output is correct |
21 |
Correct |
7 ms |
14676 KB |
Output is correct |
22 |
Correct |
8 ms |
14644 KB |
Output is correct |
23 |
Correct |
7 ms |
14676 KB |
Output is correct |
24 |
Correct |
7 ms |
14676 KB |
Output is correct |
25 |
Correct |
7 ms |
14676 KB |
Output is correct |
26 |
Correct |
7 ms |
14672 KB |
Output is correct |
27 |
Correct |
7 ms |
14548 KB |
Output is correct |
28 |
Correct |
8 ms |
14676 KB |
Output is correct |
29 |
Correct |
8 ms |
14676 KB |
Output is correct |
30 |
Correct |
8 ms |
14620 KB |
Output is correct |
31 |
Correct |
8 ms |
14676 KB |
Output is correct |
32 |
Correct |
8 ms |
14676 KB |
Output is correct |
33 |
Correct |
9 ms |
14676 KB |
Output is correct |
34 |
Correct |
8 ms |
14676 KB |
Output is correct |
35 |
Correct |
7 ms |
14676 KB |
Output is correct |
36 |
Correct |
7 ms |
14676 KB |
Output is correct |
37 |
Correct |
8 ms |
14548 KB |
Output is correct |
38 |
Correct |
8 ms |
14672 KB |
Output is correct |
39 |
Correct |
106 ms |
37692 KB |
Output is correct |
40 |
Correct |
140 ms |
37688 KB |
Output is correct |
41 |
Correct |
117 ms |
37472 KB |
Output is correct |
42 |
Correct |
133 ms |
37168 KB |
Output is correct |
43 |
Correct |
150 ms |
49832 KB |
Output is correct |
44 |
Correct |
109 ms |
40484 KB |
Output is correct |
45 |
Correct |
95 ms |
38336 KB |
Output is correct |
46 |
Correct |
56 ms |
46652 KB |
Output is correct |
47 |
Correct |
166 ms |
49356 KB |
Output is correct |
48 |
Correct |
283 ms |
91732 KB |
Output is correct |
49 |
Correct |
285 ms |
89828 KB |
Output is correct |
50 |
Correct |
160 ms |
49444 KB |
Output is correct |
51 |
Correct |
165 ms |
49444 KB |
Output is correct |
52 |
Correct |
239 ms |
49540 KB |
Output is correct |
53 |
Correct |
241 ms |
54536 KB |
Output is correct |
54 |
Correct |
321 ms |
87312 KB |
Output is correct |
55 |
Correct |
18 ms |
17748 KB |
Output is correct |
56 |
Correct |
13 ms |
16340 KB |
Output is correct |
57 |
Correct |
59 ms |
35068 KB |
Output is correct |
58 |
Correct |
46 ms |
28400 KB |
Output is correct |
59 |
Correct |
78 ms |
52920 KB |
Output is correct |
60 |
Correct |
249 ms |
90332 KB |
Output is correct |
61 |
Correct |
186 ms |
52892 KB |
Output is correct |
62 |
Correct |
175 ms |
49456 KB |
Output is correct |
63 |
Correct |
242 ms |
49472 KB |
Output is correct |
64 |
Correct |
428 ms |
104700 KB |
Output is correct |
65 |
Correct |
402 ms |
102724 KB |
Output is correct |
66 |
Correct |
268 ms |
85872 KB |
Output is correct |
67 |
Correct |
153 ms |
43916 KB |
Output is correct |
68 |
Correct |
326 ms |
66440 KB |
Output is correct |
69 |
Correct |
382 ms |
71568 KB |
Output is correct |
70 |
Correct |
319 ms |
64324 KB |
Output is correct |