# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1000784 |
2024-06-18T08:43:52 Z |
saayan007 |
Race (IOI11_race) |
C++17 |
|
265 ms |
32616 KB |
#include "race.h"
#include "bits/stdc++.h"
using namespace std;
const int mxN = 2e5L + 10;
const int mxK = 1e6L + 10;
int n, k;
vector<pair<int, int>> adj[mxN];
int ans = mxN;
int sz[mxN];
bool proc[mxN] = {};
int dp[mxK];
int get_sz(int x, int p) {
sz[x] = 1;
for(auto [y, w] : adj[x]) {
if(proc[y] || y == p) continue;
sz[x] += get_sz(y, x);
}
return sz[x];
}
int get_cen(int x, int p, int tot) {
for(auto [y, w] : adj[x]) {
if(proc[y] || y == p || sz[y] * 2 <= tot) continue;
return get_cen(y, x, tot);
}
return x;
}
void dfs(int x, int p, int dep, int dis, int flag) {
if(dis > k) return;
if(flag == 0) {
if(dp[k - dis] != mxN) ans = min(ans, dep + dp[k - dis]);
}
else if(flag == 1) {
dp[dis] = min(dp[dis], dep);
}
else if(flag == 2) {
dp[dis] = mxN;
}
for(auto [y, w] : adj[x]) {
if(proc[y] || y == p) continue;
dfs(y, x, dep + 1, dis + w, flag);
}
}
void solve(int x = 1, int p = -1) {
int c = get_cen(x, p, get_sz(x, p));
dp[0] = 0;
for(auto [d, w] : adj[c]) {
if(proc[d]) continue;
dfs(d, c, 1, w, 0);
dfs(d, c, 1, w, 1);
}
for(auto [d, w] : adj[c]) {
if(proc[d]) continue;
dfs(d, c, 1, w, 2);
}
dp[0] = mxN;
proc[c] = 1;
for(auto [d, w] : adj[c]) {
if(proc[d]) continue;
solve(d, c);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
/* rep(i, 0, mxK - 1) dp[i] = mxN; */
for(int i = 0; i < mxK; ++i) dp[i] = mxN;
n = N; k = K;
/* rep(i, 0, n - 2) { */
for(int i = 0; i < n - 1; ++i) {
adj[H[i][0] + 1].emplace_back(H[i][1] + 1, L[i]);
adj[H[i][1] + 1].emplace_back(H[i][0] + 1, L[i]);
}
solve();
return (ans > n - 1 ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9308 KB |
Output is correct |
2 |
Correct |
3 ms |
9308 KB |
Output is correct |
3 |
Correct |
3 ms |
9308 KB |
Output is correct |
4 |
Correct |
3 ms |
9304 KB |
Output is correct |
5 |
Correct |
4 ms |
9308 KB |
Output is correct |
6 |
Correct |
4 ms |
9308 KB |
Output is correct |
7 |
Correct |
3 ms |
9308 KB |
Output is correct |
8 |
Correct |
4 ms |
9308 KB |
Output is correct |
9 |
Correct |
3 ms |
9308 KB |
Output is correct |
10 |
Correct |
3 ms |
9308 KB |
Output is correct |
11 |
Correct |
3 ms |
9308 KB |
Output is correct |
12 |
Correct |
3 ms |
9308 KB |
Output is correct |
13 |
Correct |
3 ms |
9388 KB |
Output is correct |
14 |
Correct |
3 ms |
9308 KB |
Output is correct |
15 |
Correct |
3 ms |
9308 KB |
Output is correct |
16 |
Correct |
3 ms |
9308 KB |
Output is correct |
17 |
Correct |
4 ms |
9308 KB |
Output is correct |
18 |
Correct |
3 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9308 KB |
Output is correct |
2 |
Correct |
3 ms |
9308 KB |
Output is correct |
3 |
Correct |
3 ms |
9308 KB |
Output is correct |
4 |
Correct |
3 ms |
9304 KB |
Output is correct |
5 |
Correct |
4 ms |
9308 KB |
Output is correct |
6 |
Correct |
4 ms |
9308 KB |
Output is correct |
7 |
Correct |
3 ms |
9308 KB |
Output is correct |
8 |
Correct |
4 ms |
9308 KB |
Output is correct |
9 |
Correct |
3 ms |
9308 KB |
Output is correct |
10 |
Correct |
3 ms |
9308 KB |
Output is correct |
11 |
Correct |
3 ms |
9308 KB |
Output is correct |
12 |
Correct |
3 ms |
9308 KB |
Output is correct |
13 |
Correct |
3 ms |
9388 KB |
Output is correct |
14 |
Correct |
3 ms |
9308 KB |
Output is correct |
15 |
Correct |
3 ms |
9308 KB |
Output is correct |
16 |
Correct |
3 ms |
9308 KB |
Output is correct |
17 |
Correct |
4 ms |
9308 KB |
Output is correct |
18 |
Correct |
3 ms |
9308 KB |
Output is correct |
19 |
Correct |
3 ms |
9304 KB |
Output is correct |
20 |
Correct |
3 ms |
9308 KB |
Output is correct |
21 |
Correct |
3 ms |
9308 KB |
Output is correct |
22 |
Correct |
4 ms |
9308 KB |
Output is correct |
23 |
Correct |
3 ms |
10952 KB |
Output is correct |
24 |
Correct |
3 ms |
10844 KB |
Output is correct |
25 |
Correct |
4 ms |
9308 KB |
Output is correct |
26 |
Correct |
4 ms |
9308 KB |
Output is correct |
27 |
Correct |
3 ms |
9308 KB |
Output is correct |
28 |
Correct |
4 ms |
9308 KB |
Output is correct |
29 |
Correct |
3 ms |
9308 KB |
Output is correct |
30 |
Correct |
4 ms |
9304 KB |
Output is correct |
31 |
Correct |
3 ms |
10844 KB |
Output is correct |
32 |
Correct |
3 ms |
10844 KB |
Output is correct |
33 |
Correct |
4 ms |
9308 KB |
Output is correct |
34 |
Correct |
3 ms |
9308 KB |
Output is correct |
35 |
Correct |
4 ms |
9308 KB |
Output is correct |
36 |
Correct |
4 ms |
9308 KB |
Output is correct |
37 |
Correct |
3 ms |
10844 KB |
Output is correct |
38 |
Correct |
3 ms |
9204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9308 KB |
Output is correct |
2 |
Correct |
3 ms |
9308 KB |
Output is correct |
3 |
Correct |
3 ms |
9308 KB |
Output is correct |
4 |
Correct |
3 ms |
9304 KB |
Output is correct |
5 |
Correct |
4 ms |
9308 KB |
Output is correct |
6 |
Correct |
4 ms |
9308 KB |
Output is correct |
7 |
Correct |
3 ms |
9308 KB |
Output is correct |
8 |
Correct |
4 ms |
9308 KB |
Output is correct |
9 |
Correct |
3 ms |
9308 KB |
Output is correct |
10 |
Correct |
3 ms |
9308 KB |
Output is correct |
11 |
Correct |
3 ms |
9308 KB |
Output is correct |
12 |
Correct |
3 ms |
9308 KB |
Output is correct |
13 |
Correct |
3 ms |
9388 KB |
Output is correct |
14 |
Correct |
3 ms |
9308 KB |
Output is correct |
15 |
Correct |
3 ms |
9308 KB |
Output is correct |
16 |
Correct |
3 ms |
9308 KB |
Output is correct |
17 |
Correct |
4 ms |
9308 KB |
Output is correct |
18 |
Correct |
3 ms |
9308 KB |
Output is correct |
19 |
Correct |
82 ms |
14672 KB |
Output is correct |
20 |
Correct |
79 ms |
15700 KB |
Output is correct |
21 |
Correct |
92 ms |
16976 KB |
Output is correct |
22 |
Correct |
79 ms |
15884 KB |
Output is correct |
23 |
Correct |
42 ms |
16220 KB |
Output is correct |
24 |
Correct |
34 ms |
15952 KB |
Output is correct |
25 |
Correct |
79 ms |
18516 KB |
Output is correct |
26 |
Correct |
69 ms |
22608 KB |
Output is correct |
27 |
Correct |
92 ms |
21284 KB |
Output is correct |
28 |
Correct |
140 ms |
32616 KB |
Output is correct |
29 |
Correct |
140 ms |
32084 KB |
Output is correct |
30 |
Correct |
91 ms |
21976 KB |
Output is correct |
31 |
Correct |
99 ms |
21900 KB |
Output is correct |
32 |
Correct |
105 ms |
21840 KB |
Output is correct |
33 |
Correct |
121 ms |
21020 KB |
Output is correct |
34 |
Correct |
101 ms |
22888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9308 KB |
Output is correct |
2 |
Correct |
3 ms |
9308 KB |
Output is correct |
3 |
Correct |
3 ms |
9308 KB |
Output is correct |
4 |
Correct |
3 ms |
9304 KB |
Output is correct |
5 |
Correct |
4 ms |
9308 KB |
Output is correct |
6 |
Correct |
4 ms |
9308 KB |
Output is correct |
7 |
Correct |
3 ms |
9308 KB |
Output is correct |
8 |
Correct |
4 ms |
9308 KB |
Output is correct |
9 |
Correct |
3 ms |
9308 KB |
Output is correct |
10 |
Correct |
3 ms |
9308 KB |
Output is correct |
11 |
Correct |
3 ms |
9308 KB |
Output is correct |
12 |
Correct |
3 ms |
9308 KB |
Output is correct |
13 |
Correct |
3 ms |
9388 KB |
Output is correct |
14 |
Correct |
3 ms |
9308 KB |
Output is correct |
15 |
Correct |
3 ms |
9308 KB |
Output is correct |
16 |
Correct |
3 ms |
9308 KB |
Output is correct |
17 |
Correct |
4 ms |
9308 KB |
Output is correct |
18 |
Correct |
3 ms |
9308 KB |
Output is correct |
19 |
Correct |
3 ms |
9304 KB |
Output is correct |
20 |
Correct |
3 ms |
9308 KB |
Output is correct |
21 |
Correct |
3 ms |
9308 KB |
Output is correct |
22 |
Correct |
4 ms |
9308 KB |
Output is correct |
23 |
Correct |
3 ms |
10952 KB |
Output is correct |
24 |
Correct |
3 ms |
10844 KB |
Output is correct |
25 |
Correct |
4 ms |
9308 KB |
Output is correct |
26 |
Correct |
4 ms |
9308 KB |
Output is correct |
27 |
Correct |
3 ms |
9308 KB |
Output is correct |
28 |
Correct |
4 ms |
9308 KB |
Output is correct |
29 |
Correct |
3 ms |
9308 KB |
Output is correct |
30 |
Correct |
4 ms |
9304 KB |
Output is correct |
31 |
Correct |
3 ms |
10844 KB |
Output is correct |
32 |
Correct |
3 ms |
10844 KB |
Output is correct |
33 |
Correct |
4 ms |
9308 KB |
Output is correct |
34 |
Correct |
3 ms |
9308 KB |
Output is correct |
35 |
Correct |
4 ms |
9308 KB |
Output is correct |
36 |
Correct |
4 ms |
9308 KB |
Output is correct |
37 |
Correct |
3 ms |
10844 KB |
Output is correct |
38 |
Correct |
3 ms |
9204 KB |
Output is correct |
39 |
Correct |
82 ms |
14672 KB |
Output is correct |
40 |
Correct |
79 ms |
15700 KB |
Output is correct |
41 |
Correct |
92 ms |
16976 KB |
Output is correct |
42 |
Correct |
79 ms |
15884 KB |
Output is correct |
43 |
Correct |
42 ms |
16220 KB |
Output is correct |
44 |
Correct |
34 ms |
15952 KB |
Output is correct |
45 |
Correct |
79 ms |
18516 KB |
Output is correct |
46 |
Correct |
69 ms |
22608 KB |
Output is correct |
47 |
Correct |
92 ms |
21284 KB |
Output is correct |
48 |
Correct |
140 ms |
32616 KB |
Output is correct |
49 |
Correct |
140 ms |
32084 KB |
Output is correct |
50 |
Correct |
91 ms |
21976 KB |
Output is correct |
51 |
Correct |
99 ms |
21900 KB |
Output is correct |
52 |
Correct |
105 ms |
21840 KB |
Output is correct |
53 |
Correct |
121 ms |
21020 KB |
Output is correct |
54 |
Correct |
101 ms |
22888 KB |
Output is correct |
55 |
Correct |
9 ms |
9820 KB |
Output is correct |
56 |
Correct |
9 ms |
9932 KB |
Output is correct |
57 |
Correct |
51 ms |
14940 KB |
Output is correct |
58 |
Correct |
23 ms |
17612 KB |
Output is correct |
59 |
Correct |
73 ms |
21076 KB |
Output is correct |
60 |
Correct |
247 ms |
32212 KB |
Output is correct |
61 |
Correct |
101 ms |
21328 KB |
Output is correct |
62 |
Correct |
133 ms |
21872 KB |
Output is correct |
63 |
Correct |
136 ms |
23500 KB |
Output is correct |
64 |
Correct |
265 ms |
22096 KB |
Output is correct |
65 |
Correct |
100 ms |
24408 KB |
Output is correct |
66 |
Correct |
205 ms |
29960 KB |
Output is correct |
67 |
Correct |
56 ms |
25024 KB |
Output is correct |
68 |
Correct |
128 ms |
22384 KB |
Output is correct |
69 |
Correct |
119 ms |
20244 KB |
Output is correct |
70 |
Correct |
112 ms |
23868 KB |
Output is correct |