# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
495726 |
2021-12-20T03:44:27 Z |
Pietra |
Race (IOI11_race) |
C++14 |
|
597 ms |
34016 KB |
#include<bits/stdc++.h>
using namespace std ;
#include "race.h"
const int inf = 1e9 + 5 ;
const int maxn = 2e5 + 5 ;
const int MAXN = 1e6 + 5 ;
int sz[maxn], mark[maxn], ans, n, k, f[MAXN] ;
vector<pair<int,int>> grafo[maxn] ;
void dfs(int v, int p){
sz[v] = 1 ;
for(auto a : grafo[v]){
if(a.first == p || mark[a.first]) continue ;
dfs(a.first, v) ;
sz[v] += sz[a.first] ;
}
}
int find_cent(int v, int p, int szz){
for(auto a : grafo[v]){
if(a.first == p || mark[a.first] || 2*sz[a.first] <= szz) continue ;
return find_cent(a.first, v, szz) ;
}
return v ;
}
void make_count(int type, int v, int p, int dist, int lvl){
if(dist > k) return ;
if(type == -1) f[dist] = inf ;
else f[dist] = min(f[dist], lvl) ;
for(auto a : grafo[v]){
if(a.first == p || mark[a.first]) continue ;
make_count(type, a.first, v, dist + a.second, lvl + 1) ;
}
}
void add(int v, int p, int dist, int lvl){
if(dist > k) return ;
ans = min(ans, f[k-dist] + lvl) ;
for(auto a : grafo[v]){
if(a.first == p || mark[a.first]) continue ;
add(a.first, v, dist + a.second, lvl+1) ;
}
}
void make_graph(int v, int p){
dfs(v, p) ;
int c = find_cent(v, p, sz[v]) ;
mark[c] = 1 ;
f[0] = 0 ;
for(auto a : grafo[c]){
if(a.first == p || mark[a.first]) continue ;
add(a.first, c, a.second, 1) ;
make_count(0, a.first, c, a.second, 1) ;
}
for(auto a : grafo[c]){
if(a.first == p || mark[a.first]) continue ;
make_count(-1, a.first, c, a.second, 1) ;
}
for(auto a : grafo[c]){
if(a.first == p || mark[a.first]) continue ;
make_graph(a.first, c) ;
}
}
int best_path(int N, int K, int H[maxn][2], int L[maxn]) {
for(int i = 0 ; i < N - 1 ; i++){
grafo[H[i][0]].push_back({H[i][1], L[i]}) ; grafo[H[i][1]].push_back({H[i][0], L[i]}) ;
}
k = K ;
for(int i = 1 ; i <= K ; i++) f[i] = inf ;
ans = inf ;
make_graph(0, -1) ;
return (ans == inf ? -1 : ans) ;
}
// int32_t main(){
// ans = inf ;
// cin >> n >> k ;
// for(int i = 0 ; i < n-1 ; i++){
// int a, b, c ;
// cin >> a >> b >> c ;
// grafo[a].push_back({b, c}), grafo[b].push_back({a, c}) ;
// }
// for(int i = 1 ; i <= k ; i++) f[i] = inf ;
// make_graph(0, -1) ;
// cout << ans << "\n" ;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5036 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
2 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
2 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5036 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
2 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
2 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
5068 KB |
Output is correct |
22 |
Correct |
4 ms |
8652 KB |
Output is correct |
23 |
Correct |
5 ms |
7968 KB |
Output is correct |
24 |
Correct |
5 ms |
8336 KB |
Output is correct |
25 |
Correct |
5 ms |
8268 KB |
Output is correct |
26 |
Correct |
5 ms |
6348 KB |
Output is correct |
27 |
Correct |
5 ms |
8140 KB |
Output is correct |
28 |
Correct |
4 ms |
5836 KB |
Output is correct |
29 |
Correct |
4 ms |
6348 KB |
Output is correct |
30 |
Correct |
4 ms |
6476 KB |
Output is correct |
31 |
Correct |
4 ms |
7628 KB |
Output is correct |
32 |
Correct |
5 ms |
7756 KB |
Output is correct |
33 |
Correct |
5 ms |
8012 KB |
Output is correct |
34 |
Correct |
4 ms |
7372 KB |
Output is correct |
35 |
Correct |
5 ms |
8140 KB |
Output is correct |
36 |
Correct |
6 ms |
8652 KB |
Output is correct |
37 |
Correct |
5 ms |
8140 KB |
Output is correct |
38 |
Correct |
5 ms |
7060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5036 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
2 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
2 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
158 ms |
10624 KB |
Output is correct |
20 |
Correct |
119 ms |
10560 KB |
Output is correct |
21 |
Correct |
154 ms |
10644 KB |
Output is correct |
22 |
Correct |
119 ms |
10696 KB |
Output is correct |
23 |
Correct |
71 ms |
10876 KB |
Output is correct |
24 |
Correct |
59 ms |
10696 KB |
Output is correct |
25 |
Correct |
135 ms |
14124 KB |
Output is correct |
26 |
Correct |
103 ms |
17880 KB |
Output is correct |
27 |
Correct |
180 ms |
16428 KB |
Output is correct |
28 |
Correct |
308 ms |
30852 KB |
Output is correct |
29 |
Correct |
245 ms |
29604 KB |
Output is correct |
30 |
Correct |
179 ms |
16352 KB |
Output is correct |
31 |
Correct |
176 ms |
16488 KB |
Output is correct |
32 |
Correct |
213 ms |
16468 KB |
Output is correct |
33 |
Correct |
238 ms |
15360 KB |
Output is correct |
34 |
Correct |
194 ms |
15320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5036 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
2 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
2 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
5068 KB |
Output is correct |
22 |
Correct |
4 ms |
8652 KB |
Output is correct |
23 |
Correct |
5 ms |
7968 KB |
Output is correct |
24 |
Correct |
5 ms |
8336 KB |
Output is correct |
25 |
Correct |
5 ms |
8268 KB |
Output is correct |
26 |
Correct |
5 ms |
6348 KB |
Output is correct |
27 |
Correct |
5 ms |
8140 KB |
Output is correct |
28 |
Correct |
4 ms |
5836 KB |
Output is correct |
29 |
Correct |
4 ms |
6348 KB |
Output is correct |
30 |
Correct |
4 ms |
6476 KB |
Output is correct |
31 |
Correct |
4 ms |
7628 KB |
Output is correct |
32 |
Correct |
5 ms |
7756 KB |
Output is correct |
33 |
Correct |
5 ms |
8012 KB |
Output is correct |
34 |
Correct |
4 ms |
7372 KB |
Output is correct |
35 |
Correct |
5 ms |
8140 KB |
Output is correct |
36 |
Correct |
6 ms |
8652 KB |
Output is correct |
37 |
Correct |
5 ms |
8140 KB |
Output is correct |
38 |
Correct |
5 ms |
7060 KB |
Output is correct |
39 |
Correct |
158 ms |
10624 KB |
Output is correct |
40 |
Correct |
119 ms |
10560 KB |
Output is correct |
41 |
Correct |
154 ms |
10644 KB |
Output is correct |
42 |
Correct |
119 ms |
10696 KB |
Output is correct |
43 |
Correct |
71 ms |
10876 KB |
Output is correct |
44 |
Correct |
59 ms |
10696 KB |
Output is correct |
45 |
Correct |
135 ms |
14124 KB |
Output is correct |
46 |
Correct |
103 ms |
17880 KB |
Output is correct |
47 |
Correct |
180 ms |
16428 KB |
Output is correct |
48 |
Correct |
308 ms |
30852 KB |
Output is correct |
49 |
Correct |
245 ms |
29604 KB |
Output is correct |
50 |
Correct |
179 ms |
16352 KB |
Output is correct |
51 |
Correct |
176 ms |
16488 KB |
Output is correct |
52 |
Correct |
213 ms |
16468 KB |
Output is correct |
53 |
Correct |
238 ms |
15360 KB |
Output is correct |
54 |
Correct |
194 ms |
15320 KB |
Output is correct |
55 |
Correct |
10 ms |
5580 KB |
Output is correct |
56 |
Correct |
11 ms |
5464 KB |
Output is correct |
57 |
Correct |
81 ms |
10860 KB |
Output is correct |
58 |
Correct |
33 ms |
10848 KB |
Output is correct |
59 |
Correct |
96 ms |
18744 KB |
Output is correct |
60 |
Correct |
506 ms |
34016 KB |
Output is correct |
61 |
Correct |
185 ms |
16472 KB |
Output is correct |
62 |
Correct |
216 ms |
20344 KB |
Output is correct |
63 |
Correct |
310 ms |
20360 KB |
Output is correct |
64 |
Correct |
597 ms |
18268 KB |
Output is correct |
65 |
Correct |
248 ms |
16404 KB |
Output is correct |
66 |
Correct |
432 ms |
30892 KB |
Output is correct |
67 |
Correct |
110 ms |
20612 KB |
Output is correct |
68 |
Correct |
264 ms |
20384 KB |
Output is correct |
69 |
Correct |
293 ms |
20528 KB |
Output is correct |
70 |
Correct |
262 ms |
20056 KB |
Output is correct |