# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100701 |
2019-03-13T14:28:10 Z |
arman_ferdous |
Race (IOI11_race) |
C++17 |
|
3000 ms |
34072 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5+10;
const int MAX = 1e6+10;
int n, k;
vector< pair<int,int> > g[200010];
int sub[N];
bool Deleted[N];
void dfs(int u, int f) {
sub[u] = 1;
for(auto it : g[u]) if(it.first != f && !Deleted[it.first]) {
dfs(it.first, u);
sub[u] += sub[it.first];
}
}
int get_centroid(int u, int f, int lim) {
int ret = -1;
for(auto it : g[u]) if(it.first != f && !Deleted[it.first]) {
if(sub[it.first] * 2 > lim) {
ret = get_centroid(it.first, u, lim);
break;
}
} if(ret == -1) return u;
return ret;
}
int F[MAX];
int get_subtree(int u, int f, ll cost, int cnt) {
int ret = N + N;
if(cost <= k) ret = F[k - cost] + cnt;
if(cost == k) ret = min(ret, cnt);
for(auto it : g[u]) if(it.first != f && !Deleted[it.first])
ret = min(ret, get_subtree(it.first, u, cost + it.second, cnt + 1));
return ret;
}
void upd_subtree(int u, int f, ll cost, int cnt) {
if(cost < MAX) F[cost] = min(F[cost], cnt);
for(auto it : g[u]) if(it.first != f && !Deleted[it.first])
upd_subtree(it.first, u, cost + it.second, cnt + 1);
}
int calc(int u) {
for(int i = 0; i <= k; i++) F[i] = N+N;
int ans = N + N;
for(auto it : g[u]) if(!Deleted[it.first]) {
ans = min(ans, get_subtree(it.first, u, it.second, 1));
upd_subtree(it.first, u, it.second, 1);
} return ans;
}
int solve(int s) {
dfs(s,-1);
int u = get_centroid(s, -1, sub[s]);
int ret = calc(u);
Deleted[u] = true;
for(auto it : g[u]) if(!Deleted[it.first])
ret = min(ret, solve(it.first));
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]});
}
int ans = solve(0);
if(ans >= N+N) return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
7 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
6 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
7 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
6 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
7 ms |
4992 KB |
Output is correct |
20 |
Correct |
8 ms |
5120 KB |
Output is correct |
21 |
Correct |
8 ms |
5120 KB |
Output is correct |
22 |
Correct |
452 ms |
9080 KB |
Output is correct |
23 |
Correct |
338 ms |
8928 KB |
Output is correct |
24 |
Correct |
408 ms |
9056 KB |
Output is correct |
25 |
Correct |
399 ms |
8540 KB |
Output is correct |
26 |
Correct |
171 ms |
8848 KB |
Output is correct |
27 |
Correct |
466 ms |
8312 KB |
Output is correct |
28 |
Correct |
115 ms |
6648 KB |
Output is correct |
29 |
Correct |
224 ms |
6904 KB |
Output is correct |
30 |
Correct |
231 ms |
6912 KB |
Output is correct |
31 |
Correct |
339 ms |
7680 KB |
Output is correct |
32 |
Correct |
430 ms |
7900 KB |
Output is correct |
33 |
Correct |
404 ms |
8312 KB |
Output is correct |
34 |
Correct |
268 ms |
8824 KB |
Output is correct |
35 |
Correct |
370 ms |
8976 KB |
Output is correct |
36 |
Correct |
436 ms |
9080 KB |
Output is correct |
37 |
Correct |
319 ms |
8312 KB |
Output is correct |
38 |
Correct |
224 ms |
7160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
7 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
6 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
239 ms |
11768 KB |
Output is correct |
20 |
Correct |
244 ms |
11640 KB |
Output is correct |
21 |
Correct |
219 ms |
11660 KB |
Output is correct |
22 |
Correct |
172 ms |
11896 KB |
Output is correct |
23 |
Correct |
181 ms |
12028 KB |
Output is correct |
24 |
Correct |
124 ms |
12024 KB |
Output is correct |
25 |
Correct |
286 ms |
15224 KB |
Output is correct |
26 |
Correct |
123 ms |
17400 KB |
Output is correct |
27 |
Correct |
368 ms |
18936 KB |
Output is correct |
28 |
Correct |
813 ms |
34072 KB |
Output is correct |
29 |
Correct |
797 ms |
33148 KB |
Output is correct |
30 |
Correct |
345 ms |
18808 KB |
Output is correct |
31 |
Correct |
310 ms |
18808 KB |
Output is correct |
32 |
Correct |
374 ms |
18952 KB |
Output is correct |
33 |
Correct |
518 ms |
17784 KB |
Output is correct |
34 |
Correct |
633 ms |
22392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4992 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
7 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
6 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
7 ms |
4992 KB |
Output is correct |
20 |
Correct |
8 ms |
5120 KB |
Output is correct |
21 |
Correct |
8 ms |
5120 KB |
Output is correct |
22 |
Correct |
452 ms |
9080 KB |
Output is correct |
23 |
Correct |
338 ms |
8928 KB |
Output is correct |
24 |
Correct |
408 ms |
9056 KB |
Output is correct |
25 |
Correct |
399 ms |
8540 KB |
Output is correct |
26 |
Correct |
171 ms |
8848 KB |
Output is correct |
27 |
Correct |
466 ms |
8312 KB |
Output is correct |
28 |
Correct |
115 ms |
6648 KB |
Output is correct |
29 |
Correct |
224 ms |
6904 KB |
Output is correct |
30 |
Correct |
231 ms |
6912 KB |
Output is correct |
31 |
Correct |
339 ms |
7680 KB |
Output is correct |
32 |
Correct |
430 ms |
7900 KB |
Output is correct |
33 |
Correct |
404 ms |
8312 KB |
Output is correct |
34 |
Correct |
268 ms |
8824 KB |
Output is correct |
35 |
Correct |
370 ms |
8976 KB |
Output is correct |
36 |
Correct |
436 ms |
9080 KB |
Output is correct |
37 |
Correct |
319 ms |
8312 KB |
Output is correct |
38 |
Correct |
224 ms |
7160 KB |
Output is correct |
39 |
Correct |
239 ms |
11768 KB |
Output is correct |
40 |
Correct |
244 ms |
11640 KB |
Output is correct |
41 |
Correct |
219 ms |
11660 KB |
Output is correct |
42 |
Correct |
172 ms |
11896 KB |
Output is correct |
43 |
Correct |
181 ms |
12028 KB |
Output is correct |
44 |
Correct |
124 ms |
12024 KB |
Output is correct |
45 |
Correct |
286 ms |
15224 KB |
Output is correct |
46 |
Correct |
123 ms |
17400 KB |
Output is correct |
47 |
Correct |
368 ms |
18936 KB |
Output is correct |
48 |
Correct |
813 ms |
34072 KB |
Output is correct |
49 |
Correct |
797 ms |
33148 KB |
Output is correct |
50 |
Correct |
345 ms |
18808 KB |
Output is correct |
51 |
Correct |
310 ms |
18808 KB |
Output is correct |
52 |
Correct |
374 ms |
18952 KB |
Output is correct |
53 |
Correct |
518 ms |
17784 KB |
Output is correct |
54 |
Correct |
633 ms |
22392 KB |
Output is correct |
55 |
Correct |
40 ms |
5764 KB |
Output is correct |
56 |
Correct |
18 ms |
5632 KB |
Output is correct |
57 |
Correct |
85 ms |
11896 KB |
Output is correct |
58 |
Correct |
60 ms |
11628 KB |
Output is correct |
59 |
Execution timed out |
3033 ms |
18140 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |