# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527735 |
2022-02-18T06:21:59 Z |
KindaNameless |
Race (IOI11_race) |
C++14 |
|
959 ms |
39176 KB |
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<deque>
#include<cmath>
#include<map>
#include<set>
using namespace std;
#define ll long long
struct centroid_tree{
vector<vector<pair<int, int>>> adj;
vector<bool> vis;
vector<int> par, sz;
vector<ll> cnt;
map<int, int> paths;
int N, K, answer;
void init(int _N, int len){
int N = _N; K = len;
adj = vector<vector<pair<int, int>>>(N+2, vector<pair<int, int>>());
vis = vector<bool>(N+2);
par = vector<int>(N+2);
sz = vector<int>(N+2);
answer = 1e9;
}
void edge(int u, int v, int w){
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, w));
}
int get_size(int cur, int p = -1){
sz[cur] = 1;
for(pair<int, int> ch : adj[cur]){
if(ch.first != p && !vis[ch.first]){
sz[cur] += get_size(ch.first, cur);
}
}
return sz[cur];
}
int find_centroid(int cur, int p, int total){
for(pair<int, int> ch : adj[cur]){
if(sz[ch.first] > total/2 && ch.first != p && !vis[ch.first]){
return find_centroid(ch.first, cur, total);
}
}
return cur;
}
void calc(int cur, int p, int depth, int step, int flag){
if(depth > K)return;
if(flag){
if(!paths.count(depth)){
paths[depth] = step;
}
else{
paths[depth] = min(paths[depth], step);
}
}
else{
if(paths.count(K - depth)){
answer = min(answer, step + paths[K - depth]);
}
}
for(pair<int, int> ch : adj[cur]){
if(ch.first != p && !vis[ch.first]){
calc(ch.first, cur, depth + ch.second, step + 1, flag);
}
}
}
void build(int cur = 1, int p = -1){
get_size(cur);
int cen = find_centroid(cur, p, sz[cur]);
vis[cen] = 1;
par[cen] = p;
paths[0] = 0;
for(pair<int, int> ch : adj[cen]){
if(!vis[ch.first]){
calc(ch.first, cen, ch.second, 1, 0);
calc(ch.first, cen, ch.second, 1, 1);
}
}
paths.clear();
for(pair<int, int> ch : adj[cen]){
if(!vis[ch.first]){
build(ch.first, cen);
}
}
}
};
centroid_tree CT;
int best_path(int N, int K, int H[][2], int L[]){
CT.init(N, K);
for(int i = 0; i < N-1; ++i){
int u = H[i][0] + 1, v = H[i][1] + 1;
CT.edge(u, v, L[i]);
}
CT.build();
int answer = CT.answer;
return (answer == 1e9 ? -1 : answer);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
424 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
436 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
2 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
308 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
199 ms |
9144 KB |
Output is correct |
20 |
Correct |
173 ms |
9060 KB |
Output is correct |
21 |
Correct |
241 ms |
9132 KB |
Output is correct |
22 |
Correct |
183 ms |
9288 KB |
Output is correct |
23 |
Correct |
85 ms |
9412 KB |
Output is correct |
24 |
Correct |
79 ms |
9284 KB |
Output is correct |
25 |
Correct |
148 ms |
10820 KB |
Output is correct |
26 |
Correct |
100 ms |
14900 KB |
Output is correct |
27 |
Correct |
195 ms |
17360 KB |
Output is correct |
28 |
Correct |
287 ms |
24104 KB |
Output is correct |
29 |
Correct |
288 ms |
23540 KB |
Output is correct |
30 |
Correct |
213 ms |
17380 KB |
Output is correct |
31 |
Correct |
212 ms |
17396 KB |
Output is correct |
32 |
Correct |
238 ms |
17404 KB |
Output is correct |
33 |
Correct |
267 ms |
16164 KB |
Output is correct |
34 |
Correct |
196 ms |
16072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
424 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
436 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
2 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
308 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
436 KB |
Output is correct |
39 |
Correct |
199 ms |
9144 KB |
Output is correct |
40 |
Correct |
173 ms |
9060 KB |
Output is correct |
41 |
Correct |
241 ms |
9132 KB |
Output is correct |
42 |
Correct |
183 ms |
9288 KB |
Output is correct |
43 |
Correct |
85 ms |
9412 KB |
Output is correct |
44 |
Correct |
79 ms |
9284 KB |
Output is correct |
45 |
Correct |
148 ms |
10820 KB |
Output is correct |
46 |
Correct |
100 ms |
14900 KB |
Output is correct |
47 |
Correct |
195 ms |
17360 KB |
Output is correct |
48 |
Correct |
287 ms |
24104 KB |
Output is correct |
49 |
Correct |
288 ms |
23540 KB |
Output is correct |
50 |
Correct |
213 ms |
17380 KB |
Output is correct |
51 |
Correct |
212 ms |
17396 KB |
Output is correct |
52 |
Correct |
238 ms |
17404 KB |
Output is correct |
53 |
Correct |
267 ms |
16164 KB |
Output is correct |
54 |
Correct |
196 ms |
16072 KB |
Output is correct |
55 |
Correct |
17 ms |
1356 KB |
Output is correct |
56 |
Correct |
14 ms |
1236 KB |
Output is correct |
57 |
Correct |
137 ms |
9448 KB |
Output is correct |
58 |
Correct |
56 ms |
9096 KB |
Output is correct |
59 |
Correct |
316 ms |
18400 KB |
Output is correct |
60 |
Correct |
889 ms |
39176 KB |
Output is correct |
61 |
Correct |
278 ms |
19728 KB |
Output is correct |
62 |
Correct |
296 ms |
19616 KB |
Output is correct |
63 |
Correct |
343 ms |
19616 KB |
Output is correct |
64 |
Correct |
959 ms |
24288 KB |
Output is correct |
65 |
Correct |
220 ms |
20388 KB |
Output is correct |
66 |
Correct |
543 ms |
24712 KB |
Output is correct |
67 |
Correct |
122 ms |
20108 KB |
Output is correct |
68 |
Correct |
410 ms |
23728 KB |
Output is correct |
69 |
Correct |
389 ms |
23816 KB |
Output is correct |
70 |
Correct |
400 ms |
22752 KB |
Output is correct |