# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
784685 |
2023-07-16T12:17:46 Z |
bane |
Race (IOI11_race) |
C++17 |
|
300 ms |
31764 KB |
#include<bits/stdc++.h>
#include "race.h"
#define ll long long
using namespace std;
const int maxK = (int)1e6 + 5;
struct Undirected_Graph{
int N, K, ans = (int)1e9;
vector<vector<pair<int,int>>>adj;
vector<int>Used;
vector<int>Sz;
ll dp[maxK];
vector<int>vec;
Undirected_Graph(int _N, int _K, int H[0][2], int L[]):N(_N),K(_K){
adj.resize(N);
Used.resize(N);
for (int i = 0; i <= K; i++){
dp[i] = (int)1e9;
}
Sz.resize(N);
for (int i = 0; i < N - 1; i++){
adj[H[i][1]].push_back({H[i][0], L[i]});
adj[H[i][0]].push_back({H[i][1], L[i]});
}
}
int Make(int U, int P){
Sz[U] = 1;
for (auto [f,w] : adj[U]){
if (f == P || Used[f])continue;
Sz[U] += Make(f,U);
}
return Sz[U];
}
int Who(int U, int P, int Des){
for (auto [f,w] : adj[U]){
if (f == P || Used[f])continue;
if (Sz[f] * 2 > Des)return Who(f,U,Des);
}
return U;
}
void put(int u, int p, int depth, int orz){
if (depth > K)return;
vec.push_back(depth);
dp[depth] = min(dp[depth], (ll)orz);
for (auto [f,w] : adj[u]){
if (f == p || Used[f])continue;
put(f,u,depth+w,orz+1);
}
}
void Dfs(int u, int p, int depth, int orz){
if (depth > K)return;
ans = min((ll)ans, dp[K - depth] + orz);
for (auto [f,w] : adj[u]){
if (f == p || Used[f])continue;
Dfs(f,u,depth+w,orz+1);
}
}
void Centroid_Decomposition(int U, int P){
int Centroid = Who(U,P, Make(U,P));
for (auto val : vec){
dp[val] = (int)1e9;
}
vec.clear();
dp[0] = 0;
for (auto [f,w] : adj[Centroid]){
if (Used[f] || f == P)continue;
Dfs(f,Centroid,w,1);
put(f,Centroid,w,1);
}
Used[Centroid] = 1;
for (auto [f,w] : adj[Centroid]){
if (Used[f] || f == P)continue;
Centroid_Decomposition(f,Centroid);
}
}
};
int best_path(int N, int K, int H[][2], int L[])
{
Undirected_Graph G(N,K,H,L);
G.Centroid_Decomposition(0,-1);
return (G.ans == (int)1e9 ? -1 : G.ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
3 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8068 KB |
Output is correct |
6 |
Correct |
3 ms |
8148 KB |
Output is correct |
7 |
Correct |
3 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
3 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
4 ms |
8220 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8148 KB |
Output is correct |
16 |
Correct |
3 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8148 KB |
Output is correct |
18 |
Correct |
3 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
3 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8068 KB |
Output is correct |
6 |
Correct |
3 ms |
8148 KB |
Output is correct |
7 |
Correct |
3 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
3 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
4 ms |
8220 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8148 KB |
Output is correct |
16 |
Correct |
3 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8148 KB |
Output is correct |
18 |
Correct |
3 ms |
8148 KB |
Output is correct |
19 |
Correct |
3 ms |
8020 KB |
Output is correct |
20 |
Correct |
3 ms |
8148 KB |
Output is correct |
21 |
Correct |
3 ms |
8148 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8176 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8176 KB |
Output is correct |
26 |
Correct |
4 ms |
8152 KB |
Output is correct |
27 |
Correct |
4 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8148 KB |
Output is correct |
29 |
Correct |
4 ms |
8148 KB |
Output is correct |
30 |
Correct |
4 ms |
8148 KB |
Output is correct |
31 |
Correct |
4 ms |
8148 KB |
Output is correct |
32 |
Correct |
4 ms |
8148 KB |
Output is correct |
33 |
Correct |
4 ms |
8148 KB |
Output is correct |
34 |
Correct |
4 ms |
8148 KB |
Output is correct |
35 |
Correct |
4 ms |
8148 KB |
Output is correct |
36 |
Correct |
4 ms |
8148 KB |
Output is correct |
37 |
Correct |
4 ms |
8148 KB |
Output is correct |
38 |
Correct |
4 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
3 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8068 KB |
Output is correct |
6 |
Correct |
3 ms |
8148 KB |
Output is correct |
7 |
Correct |
3 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
3 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
4 ms |
8220 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8148 KB |
Output is correct |
16 |
Correct |
3 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8148 KB |
Output is correct |
18 |
Correct |
3 ms |
8148 KB |
Output is correct |
19 |
Correct |
93 ms |
16148 KB |
Output is correct |
20 |
Correct |
83 ms |
16136 KB |
Output is correct |
21 |
Correct |
85 ms |
16476 KB |
Output is correct |
22 |
Correct |
85 ms |
16728 KB |
Output is correct |
23 |
Correct |
52 ms |
16340 KB |
Output is correct |
24 |
Correct |
41 ms |
16240 KB |
Output is correct |
25 |
Correct |
84 ms |
17704 KB |
Output is correct |
26 |
Correct |
66 ms |
20192 KB |
Output is correct |
27 |
Correct |
106 ms |
24268 KB |
Output is correct |
28 |
Correct |
165 ms |
30960 KB |
Output is correct |
29 |
Correct |
161 ms |
30324 KB |
Output is correct |
30 |
Correct |
105 ms |
24264 KB |
Output is correct |
31 |
Correct |
107 ms |
24244 KB |
Output is correct |
32 |
Correct |
174 ms |
24276 KB |
Output is correct |
33 |
Correct |
135 ms |
23032 KB |
Output is correct |
34 |
Correct |
122 ms |
22876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
3 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8068 KB |
Output is correct |
6 |
Correct |
3 ms |
8148 KB |
Output is correct |
7 |
Correct |
3 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
3 ms |
8148 KB |
Output is correct |
10 |
Correct |
3 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
4 ms |
8220 KB |
Output is correct |
14 |
Correct |
3 ms |
8148 KB |
Output is correct |
15 |
Correct |
3 ms |
8148 KB |
Output is correct |
16 |
Correct |
3 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8148 KB |
Output is correct |
18 |
Correct |
3 ms |
8148 KB |
Output is correct |
19 |
Correct |
3 ms |
8020 KB |
Output is correct |
20 |
Correct |
3 ms |
8148 KB |
Output is correct |
21 |
Correct |
3 ms |
8148 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8176 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8176 KB |
Output is correct |
26 |
Correct |
4 ms |
8152 KB |
Output is correct |
27 |
Correct |
4 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8148 KB |
Output is correct |
29 |
Correct |
4 ms |
8148 KB |
Output is correct |
30 |
Correct |
4 ms |
8148 KB |
Output is correct |
31 |
Correct |
4 ms |
8148 KB |
Output is correct |
32 |
Correct |
4 ms |
8148 KB |
Output is correct |
33 |
Correct |
4 ms |
8148 KB |
Output is correct |
34 |
Correct |
4 ms |
8148 KB |
Output is correct |
35 |
Correct |
4 ms |
8148 KB |
Output is correct |
36 |
Correct |
4 ms |
8148 KB |
Output is correct |
37 |
Correct |
4 ms |
8148 KB |
Output is correct |
38 |
Correct |
4 ms |
8148 KB |
Output is correct |
39 |
Correct |
93 ms |
16148 KB |
Output is correct |
40 |
Correct |
83 ms |
16136 KB |
Output is correct |
41 |
Correct |
85 ms |
16476 KB |
Output is correct |
42 |
Correct |
85 ms |
16728 KB |
Output is correct |
43 |
Correct |
52 ms |
16340 KB |
Output is correct |
44 |
Correct |
41 ms |
16240 KB |
Output is correct |
45 |
Correct |
84 ms |
17704 KB |
Output is correct |
46 |
Correct |
66 ms |
20192 KB |
Output is correct |
47 |
Correct |
106 ms |
24268 KB |
Output is correct |
48 |
Correct |
165 ms |
30960 KB |
Output is correct |
49 |
Correct |
161 ms |
30324 KB |
Output is correct |
50 |
Correct |
105 ms |
24264 KB |
Output is correct |
51 |
Correct |
107 ms |
24244 KB |
Output is correct |
52 |
Correct |
174 ms |
24276 KB |
Output is correct |
53 |
Correct |
135 ms |
23032 KB |
Output is correct |
54 |
Correct |
122 ms |
22876 KB |
Output is correct |
55 |
Correct |
8 ms |
8916 KB |
Output is correct |
56 |
Correct |
12 ms |
9012 KB |
Output is correct |
57 |
Correct |
55 ms |
16900 KB |
Output is correct |
58 |
Correct |
30 ms |
17264 KB |
Output is correct |
59 |
Correct |
78 ms |
20124 KB |
Output is correct |
60 |
Correct |
282 ms |
31764 KB |
Output is correct |
61 |
Correct |
134 ms |
24588 KB |
Output is correct |
62 |
Correct |
123 ms |
25292 KB |
Output is correct |
63 |
Correct |
179 ms |
25352 KB |
Output is correct |
64 |
Correct |
300 ms |
25156 KB |
Output is correct |
65 |
Correct |
128 ms |
24220 KB |
Output is correct |
66 |
Correct |
246 ms |
29076 KB |
Output is correct |
67 |
Correct |
77 ms |
26348 KB |
Output is correct |
68 |
Correct |
170 ms |
24904 KB |
Output is correct |
69 |
Correct |
172 ms |
25036 KB |
Output is correct |
70 |
Correct |
214 ms |
24288 KB |
Output is correct |