# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1067058 |
2024-08-20T10:28:07 Z |
Thunnus |
Race (IOI11_race) |
C++17 |
|
348 ms |
104396 KB |
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
const int MAXN = 2e5 + 5;
int ans = LLONG_MAX, k;
vector<map<int, int>> mp(MAXN);
inline void dfs(vector<vector<pii>> &adj, int v = 0, int p = -1, int dist = 0, int dep = 0){
for(pii &u : adj[v]){
if(u.fi == p) continue;
dfs(adj, u.fi, v, dist + u.se, dep + 1);
}
mp[v][dist] = dep;
for(pii &u : adj[v]){
if(u.fi == p) continue;
if(sz(mp[u.fi]) > sz(mp[v])) mp[v].swap(mp[u.fi]);
for(auto &it : mp[u.fi]){
if(mp[v].count(k - (it.fi - 2 * dist))){ // distance with lca
ans = min(ans, mp[v][k - (it.fi - 2 * dist)] + it.se - 2 * dep);
}
}
for(auto &it : mp[u.fi]){
if(!mp[v].count(it.fi)) mp[v][it.fi] = it.se;
else mp[v][it.fi] = min(mp[v][it.fi], it.se);
if(it.fi - dist == k){
ans = min(ans, it.se - dep);
}
}
}
}
int32_t best_path(int32_t n, int32_t K, int32_t h[][2], int32_t l[]){
k = K;
vector<vector<pii>> adj(n);
for(int i = 0; i < n - 1; i++){
adj[h[i][0]].emplace_back(h[i][1], l[i]);
adj[h[i][1]].emplace_back(h[i][0], l[i]);
}
dfs(adj);
return (ans == LLONG_MAX ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9852 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9716 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
4 ms |
9852 KB |
Output is correct |
12 |
Correct |
4 ms |
9648 KB |
Output is correct |
13 |
Correct |
4 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
4 ms |
9816 KB |
Output is correct |
16 |
Correct |
4 ms |
9820 KB |
Output is correct |
17 |
Correct |
4 ms |
10072 KB |
Output is correct |
18 |
Correct |
5 ms |
9820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9852 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9716 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
4 ms |
9852 KB |
Output is correct |
12 |
Correct |
4 ms |
9648 KB |
Output is correct |
13 |
Correct |
4 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
4 ms |
9816 KB |
Output is correct |
16 |
Correct |
4 ms |
9820 KB |
Output is correct |
17 |
Correct |
4 ms |
10072 KB |
Output is correct |
18 |
Correct |
5 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9816 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
5 ms |
10076 KB |
Output is correct |
22 |
Correct |
4 ms |
10076 KB |
Output is correct |
23 |
Correct |
5 ms |
10076 KB |
Output is correct |
24 |
Correct |
5 ms |
10072 KB |
Output is correct |
25 |
Correct |
5 ms |
10076 KB |
Output is correct |
26 |
Correct |
5 ms |
10076 KB |
Output is correct |
27 |
Correct |
4 ms |
9820 KB |
Output is correct |
28 |
Correct |
4 ms |
10076 KB |
Output is correct |
29 |
Correct |
5 ms |
10076 KB |
Output is correct |
30 |
Correct |
5 ms |
10076 KB |
Output is correct |
31 |
Correct |
5 ms |
10076 KB |
Output is correct |
32 |
Correct |
5 ms |
10116 KB |
Output is correct |
33 |
Correct |
5 ms |
10076 KB |
Output is correct |
34 |
Correct |
4 ms |
10076 KB |
Output is correct |
35 |
Correct |
5 ms |
10328 KB |
Output is correct |
36 |
Correct |
5 ms |
10076 KB |
Output is correct |
37 |
Correct |
5 ms |
9872 KB |
Output is correct |
38 |
Correct |
5 ms |
10076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9852 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9716 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
4 ms |
9852 KB |
Output is correct |
12 |
Correct |
4 ms |
9648 KB |
Output is correct |
13 |
Correct |
4 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
4 ms |
9816 KB |
Output is correct |
16 |
Correct |
4 ms |
9820 KB |
Output is correct |
17 |
Correct |
4 ms |
10072 KB |
Output is correct |
18 |
Correct |
5 ms |
9820 KB |
Output is correct |
19 |
Correct |
90 ms |
35408 KB |
Output is correct |
20 |
Correct |
90 ms |
35412 KB |
Output is correct |
21 |
Correct |
77 ms |
35060 KB |
Output is correct |
22 |
Correct |
84 ms |
34640 KB |
Output is correct |
23 |
Correct |
130 ms |
47432 KB |
Output is correct |
24 |
Correct |
92 ms |
37532 KB |
Output is correct |
25 |
Correct |
71 ms |
34452 KB |
Output is correct |
26 |
Correct |
48 ms |
41296 KB |
Output is correct |
27 |
Correct |
128 ms |
49488 KB |
Output is correct |
28 |
Correct |
214 ms |
85588 KB |
Output is correct |
29 |
Correct |
216 ms |
84136 KB |
Output is correct |
30 |
Correct |
127 ms |
49488 KB |
Output is correct |
31 |
Correct |
126 ms |
49492 KB |
Output is correct |
32 |
Correct |
152 ms |
49488 KB |
Output is correct |
33 |
Correct |
184 ms |
54280 KB |
Output is correct |
34 |
Correct |
267 ms |
87124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9820 KB |
Output is correct |
3 |
Correct |
4 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
4 ms |
9852 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9716 KB |
Output is correct |
9 |
Correct |
4 ms |
9820 KB |
Output is correct |
10 |
Correct |
4 ms |
9820 KB |
Output is correct |
11 |
Correct |
4 ms |
9852 KB |
Output is correct |
12 |
Correct |
4 ms |
9648 KB |
Output is correct |
13 |
Correct |
4 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
4 ms |
9816 KB |
Output is correct |
16 |
Correct |
4 ms |
9820 KB |
Output is correct |
17 |
Correct |
4 ms |
10072 KB |
Output is correct |
18 |
Correct |
5 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9816 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
5 ms |
10076 KB |
Output is correct |
22 |
Correct |
4 ms |
10076 KB |
Output is correct |
23 |
Correct |
5 ms |
10076 KB |
Output is correct |
24 |
Correct |
5 ms |
10072 KB |
Output is correct |
25 |
Correct |
5 ms |
10076 KB |
Output is correct |
26 |
Correct |
5 ms |
10076 KB |
Output is correct |
27 |
Correct |
4 ms |
9820 KB |
Output is correct |
28 |
Correct |
4 ms |
10076 KB |
Output is correct |
29 |
Correct |
5 ms |
10076 KB |
Output is correct |
30 |
Correct |
5 ms |
10076 KB |
Output is correct |
31 |
Correct |
5 ms |
10076 KB |
Output is correct |
32 |
Correct |
5 ms |
10116 KB |
Output is correct |
33 |
Correct |
5 ms |
10076 KB |
Output is correct |
34 |
Correct |
4 ms |
10076 KB |
Output is correct |
35 |
Correct |
5 ms |
10328 KB |
Output is correct |
36 |
Correct |
5 ms |
10076 KB |
Output is correct |
37 |
Correct |
5 ms |
9872 KB |
Output is correct |
38 |
Correct |
5 ms |
10076 KB |
Output is correct |
39 |
Correct |
90 ms |
35408 KB |
Output is correct |
40 |
Correct |
90 ms |
35412 KB |
Output is correct |
41 |
Correct |
77 ms |
35060 KB |
Output is correct |
42 |
Correct |
84 ms |
34640 KB |
Output is correct |
43 |
Correct |
130 ms |
47432 KB |
Output is correct |
44 |
Correct |
92 ms |
37532 KB |
Output is correct |
45 |
Correct |
71 ms |
34452 KB |
Output is correct |
46 |
Correct |
48 ms |
41296 KB |
Output is correct |
47 |
Correct |
128 ms |
49488 KB |
Output is correct |
48 |
Correct |
214 ms |
85588 KB |
Output is correct |
49 |
Correct |
216 ms |
84136 KB |
Output is correct |
50 |
Correct |
127 ms |
49488 KB |
Output is correct |
51 |
Correct |
126 ms |
49492 KB |
Output is correct |
52 |
Correct |
152 ms |
49488 KB |
Output is correct |
53 |
Correct |
184 ms |
54280 KB |
Output is correct |
54 |
Correct |
267 ms |
87124 KB |
Output is correct |
55 |
Correct |
14 ms |
13400 KB |
Output is correct |
56 |
Correct |
9 ms |
11868 KB |
Output is correct |
57 |
Correct |
48 ms |
32852 KB |
Output is correct |
58 |
Correct |
39 ms |
25364 KB |
Output is correct |
59 |
Correct |
70 ms |
47440 KB |
Output is correct |
60 |
Correct |
216 ms |
84264 KB |
Output is correct |
61 |
Correct |
150 ms |
52992 KB |
Output is correct |
62 |
Correct |
178 ms |
49568 KB |
Output is correct |
63 |
Correct |
152 ms |
49632 KB |
Output is correct |
64 |
Correct |
348 ms |
104396 KB |
Output is correct |
65 |
Correct |
321 ms |
102480 KB |
Output is correct |
66 |
Correct |
225 ms |
81228 KB |
Output is correct |
67 |
Correct |
114 ms |
42428 KB |
Output is correct |
68 |
Correct |
258 ms |
65872 KB |
Output is correct |
69 |
Correct |
274 ms |
70712 KB |
Output is correct |
70 |
Correct |
232 ms |
63316 KB |
Output is correct |