# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
160648 |
2019-10-29T06:05:06 Z |
jhnah917 |
Race (IOI11_race) |
C++14 |
|
635 ms |
31980 KB |
#include "race.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define pb push_back
using namespace std;
typedef pair<int, int> p;
int n, k;
vector<p> g[202020];
vector<int> init;
int sz[202020], use[202020], chk[1010101];
int getSize(int v, int par){
sz[v] = 1;
for(auto i : g[v]){
if(i.x == par || use[i.x]) continue;
sz[v] += getSize(i.x, v);
}
return sz[v];
}
int getCent(int v, int par, int cnt){
for(auto i : g[v]){
if(i.x == par || use[i.x]) continue;
if(sz[i.x] > cnt/2) return getCent(i.x, v, cnt);
}
return v;
}
void update(int now, int prv, int dst, int dep){
if(dst > k) return;
chk[dst] = min(chk[dst], dep);
init.push_back(dst);
for(auto i : g[now]){
if(i.x == prv || use[i.x]) continue;
update(i.x, now, dst + i.y, dep + 1);
}
}
int calc(int now, int prv, int dst, int dep){
int ret = 1e9+7;
if(dst > k) return ret;
if(chk[k-dst] < 1e9){
ret = chk[k-dst] + dep;
}
for(auto i : g[now]){
if(use[i.x] || i.x == prv) continue;
ret = min(ret, calc(i.x, now, dst + i.y, dep + 1));
}
return ret;
}
int solve(int v){
int cnt = getSize(v, -1);
int cent = getCent(v, -1, cnt); use[cent] = 1;
int ret = 1e9+7;
for(auto i : init){
chk[i] = 1e9+7;
}
init.clear();
chk[0] = 0;
for(auto i : g[cent]){
if(use[i.x]) continue;
//cout << "calc start\n";
ret = min(ret, calc(i.x, cent, i.y, 1));
//cout << "calc end\nupdate start\n";
update(i.x, cent, i.y, 1);
//cout << "update end\n";
}
for(auto i : g[cent]){
if(use[i.x]) continue;
ret = min(ret, solve(i.x));
}
return ret;
}
int best_path(int N, int K, int H[][2], int L[]){
n=N; k=K;
for(int i=0;i<n-1;i++){
g[H[i][0]].push_back({H[i][1],L[i]});
g[H[i][1]].push_back({H[i][0],L[i]});
}
memset(chk, 0x3f, sizeof chk);
int ans = solve(0);
if(ans > 1e9) return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9080 KB |
Output is correct |
2 |
Correct |
9 ms |
9080 KB |
Output is correct |
3 |
Correct |
9 ms |
9084 KB |
Output is correct |
4 |
Correct |
9 ms |
9080 KB |
Output is correct |
5 |
Correct |
10 ms |
9080 KB |
Output is correct |
6 |
Correct |
9 ms |
9080 KB |
Output is correct |
7 |
Correct |
10 ms |
9080 KB |
Output is correct |
8 |
Correct |
10 ms |
9080 KB |
Output is correct |
9 |
Correct |
10 ms |
9080 KB |
Output is correct |
10 |
Correct |
10 ms |
9080 KB |
Output is correct |
11 |
Correct |
10 ms |
9080 KB |
Output is correct |
12 |
Correct |
10 ms |
9080 KB |
Output is correct |
13 |
Correct |
10 ms |
8980 KB |
Output is correct |
14 |
Correct |
10 ms |
9080 KB |
Output is correct |
15 |
Correct |
10 ms |
9080 KB |
Output is correct |
16 |
Correct |
10 ms |
9084 KB |
Output is correct |
17 |
Correct |
10 ms |
9080 KB |
Output is correct |
18 |
Correct |
11 ms |
9080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9080 KB |
Output is correct |
2 |
Correct |
9 ms |
9080 KB |
Output is correct |
3 |
Correct |
9 ms |
9084 KB |
Output is correct |
4 |
Correct |
9 ms |
9080 KB |
Output is correct |
5 |
Correct |
10 ms |
9080 KB |
Output is correct |
6 |
Correct |
9 ms |
9080 KB |
Output is correct |
7 |
Correct |
10 ms |
9080 KB |
Output is correct |
8 |
Correct |
10 ms |
9080 KB |
Output is correct |
9 |
Correct |
10 ms |
9080 KB |
Output is correct |
10 |
Correct |
10 ms |
9080 KB |
Output is correct |
11 |
Correct |
10 ms |
9080 KB |
Output is correct |
12 |
Correct |
10 ms |
9080 KB |
Output is correct |
13 |
Correct |
10 ms |
8980 KB |
Output is correct |
14 |
Correct |
10 ms |
9080 KB |
Output is correct |
15 |
Correct |
10 ms |
9080 KB |
Output is correct |
16 |
Correct |
10 ms |
9084 KB |
Output is correct |
17 |
Correct |
10 ms |
9080 KB |
Output is correct |
18 |
Correct |
11 ms |
9080 KB |
Output is correct |
19 |
Correct |
10 ms |
9080 KB |
Output is correct |
20 |
Correct |
10 ms |
9080 KB |
Output is correct |
21 |
Correct |
11 ms |
9080 KB |
Output is correct |
22 |
Correct |
11 ms |
9080 KB |
Output is correct |
23 |
Correct |
11 ms |
9080 KB |
Output is correct |
24 |
Correct |
11 ms |
9080 KB |
Output is correct |
25 |
Correct |
11 ms |
9080 KB |
Output is correct |
26 |
Correct |
10 ms |
9080 KB |
Output is correct |
27 |
Correct |
10 ms |
9080 KB |
Output is correct |
28 |
Correct |
10 ms |
9080 KB |
Output is correct |
29 |
Correct |
11 ms |
9080 KB |
Output is correct |
30 |
Correct |
11 ms |
9080 KB |
Output is correct |
31 |
Correct |
12 ms |
9052 KB |
Output is correct |
32 |
Correct |
11 ms |
9080 KB |
Output is correct |
33 |
Correct |
11 ms |
9080 KB |
Output is correct |
34 |
Correct |
10 ms |
9080 KB |
Output is correct |
35 |
Correct |
10 ms |
9080 KB |
Output is correct |
36 |
Correct |
10 ms |
9080 KB |
Output is correct |
37 |
Correct |
10 ms |
9080 KB |
Output is correct |
38 |
Correct |
14 ms |
9080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9080 KB |
Output is correct |
2 |
Correct |
9 ms |
9080 KB |
Output is correct |
3 |
Correct |
9 ms |
9084 KB |
Output is correct |
4 |
Correct |
9 ms |
9080 KB |
Output is correct |
5 |
Correct |
10 ms |
9080 KB |
Output is correct |
6 |
Correct |
9 ms |
9080 KB |
Output is correct |
7 |
Correct |
10 ms |
9080 KB |
Output is correct |
8 |
Correct |
10 ms |
9080 KB |
Output is correct |
9 |
Correct |
10 ms |
9080 KB |
Output is correct |
10 |
Correct |
10 ms |
9080 KB |
Output is correct |
11 |
Correct |
10 ms |
9080 KB |
Output is correct |
12 |
Correct |
10 ms |
9080 KB |
Output is correct |
13 |
Correct |
10 ms |
8980 KB |
Output is correct |
14 |
Correct |
10 ms |
9080 KB |
Output is correct |
15 |
Correct |
10 ms |
9080 KB |
Output is correct |
16 |
Correct |
10 ms |
9084 KB |
Output is correct |
17 |
Correct |
10 ms |
9080 KB |
Output is correct |
18 |
Correct |
11 ms |
9080 KB |
Output is correct |
19 |
Correct |
171 ms |
16092 KB |
Output is correct |
20 |
Correct |
172 ms |
16120 KB |
Output is correct |
21 |
Correct |
188 ms |
16248 KB |
Output is correct |
22 |
Correct |
177 ms |
16556 KB |
Output is correct |
23 |
Correct |
120 ms |
16404 KB |
Output is correct |
24 |
Correct |
89 ms |
16376 KB |
Output is correct |
25 |
Correct |
194 ms |
18128 KB |
Output is correct |
26 |
Correct |
118 ms |
20740 KB |
Output is correct |
27 |
Correct |
227 ms |
23388 KB |
Output is correct |
28 |
Correct |
412 ms |
31736 KB |
Output is correct |
29 |
Correct |
401 ms |
31012 KB |
Output is correct |
30 |
Correct |
201 ms |
23456 KB |
Output is correct |
31 |
Correct |
212 ms |
23472 KB |
Output is correct |
32 |
Correct |
244 ms |
23532 KB |
Output is correct |
33 |
Correct |
350 ms |
22244 KB |
Output is correct |
34 |
Correct |
315 ms |
23192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9080 KB |
Output is correct |
2 |
Correct |
9 ms |
9080 KB |
Output is correct |
3 |
Correct |
9 ms |
9084 KB |
Output is correct |
4 |
Correct |
9 ms |
9080 KB |
Output is correct |
5 |
Correct |
10 ms |
9080 KB |
Output is correct |
6 |
Correct |
9 ms |
9080 KB |
Output is correct |
7 |
Correct |
10 ms |
9080 KB |
Output is correct |
8 |
Correct |
10 ms |
9080 KB |
Output is correct |
9 |
Correct |
10 ms |
9080 KB |
Output is correct |
10 |
Correct |
10 ms |
9080 KB |
Output is correct |
11 |
Correct |
10 ms |
9080 KB |
Output is correct |
12 |
Correct |
10 ms |
9080 KB |
Output is correct |
13 |
Correct |
10 ms |
8980 KB |
Output is correct |
14 |
Correct |
10 ms |
9080 KB |
Output is correct |
15 |
Correct |
10 ms |
9080 KB |
Output is correct |
16 |
Correct |
10 ms |
9084 KB |
Output is correct |
17 |
Correct |
10 ms |
9080 KB |
Output is correct |
18 |
Correct |
11 ms |
9080 KB |
Output is correct |
19 |
Correct |
10 ms |
9080 KB |
Output is correct |
20 |
Correct |
10 ms |
9080 KB |
Output is correct |
21 |
Correct |
11 ms |
9080 KB |
Output is correct |
22 |
Correct |
11 ms |
9080 KB |
Output is correct |
23 |
Correct |
11 ms |
9080 KB |
Output is correct |
24 |
Correct |
11 ms |
9080 KB |
Output is correct |
25 |
Correct |
11 ms |
9080 KB |
Output is correct |
26 |
Correct |
10 ms |
9080 KB |
Output is correct |
27 |
Correct |
10 ms |
9080 KB |
Output is correct |
28 |
Correct |
10 ms |
9080 KB |
Output is correct |
29 |
Correct |
11 ms |
9080 KB |
Output is correct |
30 |
Correct |
11 ms |
9080 KB |
Output is correct |
31 |
Correct |
12 ms |
9052 KB |
Output is correct |
32 |
Correct |
11 ms |
9080 KB |
Output is correct |
33 |
Correct |
11 ms |
9080 KB |
Output is correct |
34 |
Correct |
10 ms |
9080 KB |
Output is correct |
35 |
Correct |
10 ms |
9080 KB |
Output is correct |
36 |
Correct |
10 ms |
9080 KB |
Output is correct |
37 |
Correct |
10 ms |
9080 KB |
Output is correct |
38 |
Correct |
14 ms |
9080 KB |
Output is correct |
39 |
Correct |
171 ms |
16092 KB |
Output is correct |
40 |
Correct |
172 ms |
16120 KB |
Output is correct |
41 |
Correct |
188 ms |
16248 KB |
Output is correct |
42 |
Correct |
177 ms |
16556 KB |
Output is correct |
43 |
Correct |
120 ms |
16404 KB |
Output is correct |
44 |
Correct |
89 ms |
16376 KB |
Output is correct |
45 |
Correct |
194 ms |
18128 KB |
Output is correct |
46 |
Correct |
118 ms |
20740 KB |
Output is correct |
47 |
Correct |
227 ms |
23388 KB |
Output is correct |
48 |
Correct |
412 ms |
31736 KB |
Output is correct |
49 |
Correct |
401 ms |
31012 KB |
Output is correct |
50 |
Correct |
201 ms |
23456 KB |
Output is correct |
51 |
Correct |
212 ms |
23472 KB |
Output is correct |
52 |
Correct |
244 ms |
23532 KB |
Output is correct |
53 |
Correct |
350 ms |
22244 KB |
Output is correct |
54 |
Correct |
315 ms |
23192 KB |
Output is correct |
55 |
Correct |
20 ms |
9836 KB |
Output is correct |
56 |
Correct |
21 ms |
9976 KB |
Output is correct |
57 |
Correct |
107 ms |
16756 KB |
Output is correct |
58 |
Correct |
51 ms |
16876 KB |
Output is correct |
59 |
Correct |
120 ms |
20636 KB |
Output is correct |
60 |
Correct |
599 ms |
31980 KB |
Output is correct |
61 |
Correct |
247 ms |
23800 KB |
Output is correct |
62 |
Correct |
255 ms |
24352 KB |
Output is correct |
63 |
Correct |
337 ms |
24388 KB |
Output is correct |
64 |
Correct |
635 ms |
24684 KB |
Output is correct |
65 |
Correct |
300 ms |
24312 KB |
Output is correct |
66 |
Correct |
562 ms |
29692 KB |
Output is correct |
67 |
Correct |
158 ms |
25976 KB |
Output is correct |
68 |
Correct |
337 ms |
24856 KB |
Output is correct |
69 |
Correct |
320 ms |
24944 KB |
Output is correct |
70 |
Correct |
303 ms |
24140 KB |
Output is correct |