# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
422807 |
2021-06-10T12:41:31 Z |
ScarletS |
Race (IOI11_race) |
C++17 |
|
848 ms |
30228 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7, INF = 1e9;
int k, ans = INF, dp[1000007], sub[N];
vector<array<int,2>> e[N];
bitset<N> b;
int subDfs(int c, int p)
{
sub[c]=1;
for (auto i : e[c])
if (i[0]!=p&&!b[i[0]])
sub[c]+=subDfs(i[0],c);
return sub[c];
}
int findC(int c, int p, int t)
{
for (auto i : e[c])
if (i[0]!=p&&!b[i[0]]&&sub[i[0]]>t)
return findC(i[0],c,t);
return c;
}
void dfs(int c, int p, int h, int t, bool fill)
{
if (h>k)
return;
if (fill)
dp[h]=min(dp[h],t);
else
ans=min(ans,dp[k-h]+t);
for (auto i : e[c])
if (i[0]!=p&&!b[i[0]])
dfs(i[0],c,h+i[1],t+1,fill);
}
void undo(int c, int p, int h)
{
if (h>k)
return;
dp[h]=INF;
for (auto i : e[c])
if (i[0]!=p&&!b[i[0]])
undo(i[0],c,h+i[1]);
}
void solve(int n)
{
int c = findC(n,-1,subDfs(n,-1)/2);
b[c]=1;
for (auto i : e[c])
if (!b[i[0]])
{
dfs(i[0],c,i[1],1,0);
dfs(i[0],c,i[1],1,1);
}
for (auto i : e[c])
if (!b[i[0]])
undo(i[0],c,i[1]);
for (auto i : e[c])
if (!b[i[0]])
solve(i[0]);
}
int best_path(int n, int K, int h[][2], int l[])
{
k=K;
for (int i=0;i<n-1;++i)
{
e[h[i][0]].push_back({h[i][1],l[i]});
e[h[i][1]].push_back({h[i][0],l[i]});
}
for (int i=1;i<=k;++i)
dp[i]=INF;
solve(0);
if (ans==INF)
return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 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 |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 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 |
4 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 |
3 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 |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 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 |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 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 |
4 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 |
3 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 |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
6 ms |
8672 KB |
Output is correct |
23 |
Correct |
6 ms |
8012 KB |
Output is correct |
24 |
Correct |
6 ms |
8396 KB |
Output is correct |
25 |
Correct |
6 ms |
8396 KB |
Output is correct |
26 |
Correct |
5 ms |
6348 KB |
Output is correct |
27 |
Correct |
6 ms |
8140 KB |
Output is correct |
28 |
Correct |
5 ms |
5836 KB |
Output is correct |
29 |
Correct |
5 ms |
6348 KB |
Output is correct |
30 |
Correct |
5 ms |
6476 KB |
Output is correct |
31 |
Correct |
6 ms |
7632 KB |
Output is correct |
32 |
Correct |
6 ms |
7756 KB |
Output is correct |
33 |
Correct |
6 ms |
8136 KB |
Output is correct |
34 |
Correct |
6 ms |
7372 KB |
Output is correct |
35 |
Correct |
6 ms |
8140 KB |
Output is correct |
36 |
Correct |
6 ms |
8652 KB |
Output is correct |
37 |
Correct |
7 ms |
8140 KB |
Output is correct |
38 |
Correct |
5 ms |
6988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 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 |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 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 |
4 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 |
3 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 |
172 ms |
10232 KB |
Output is correct |
20 |
Correct |
161 ms |
10208 KB |
Output is correct |
21 |
Correct |
191 ms |
10256 KB |
Output is correct |
22 |
Correct |
166 ms |
10216 KB |
Output is correct |
23 |
Correct |
84 ms |
10492 KB |
Output is correct |
24 |
Correct |
66 ms |
10316 KB |
Output is correct |
25 |
Correct |
148 ms |
13008 KB |
Output is correct |
26 |
Correct |
112 ms |
15944 KB |
Output is correct |
27 |
Correct |
221 ms |
15784 KB |
Output is correct |
28 |
Correct |
317 ms |
26980 KB |
Output is correct |
29 |
Correct |
326 ms |
25868 KB |
Output is correct |
30 |
Correct |
220 ms |
15684 KB |
Output is correct |
31 |
Correct |
223 ms |
15648 KB |
Output is correct |
32 |
Correct |
280 ms |
15712 KB |
Output is correct |
33 |
Correct |
246 ms |
14496 KB |
Output is correct |
34 |
Correct |
244 ms |
14520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 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 |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 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 |
4 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 |
3 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 |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
6 ms |
8672 KB |
Output is correct |
23 |
Correct |
6 ms |
8012 KB |
Output is correct |
24 |
Correct |
6 ms |
8396 KB |
Output is correct |
25 |
Correct |
6 ms |
8396 KB |
Output is correct |
26 |
Correct |
5 ms |
6348 KB |
Output is correct |
27 |
Correct |
6 ms |
8140 KB |
Output is correct |
28 |
Correct |
5 ms |
5836 KB |
Output is correct |
29 |
Correct |
5 ms |
6348 KB |
Output is correct |
30 |
Correct |
5 ms |
6476 KB |
Output is correct |
31 |
Correct |
6 ms |
7632 KB |
Output is correct |
32 |
Correct |
6 ms |
7756 KB |
Output is correct |
33 |
Correct |
6 ms |
8136 KB |
Output is correct |
34 |
Correct |
6 ms |
7372 KB |
Output is correct |
35 |
Correct |
6 ms |
8140 KB |
Output is correct |
36 |
Correct |
6 ms |
8652 KB |
Output is correct |
37 |
Correct |
7 ms |
8140 KB |
Output is correct |
38 |
Correct |
5 ms |
6988 KB |
Output is correct |
39 |
Correct |
172 ms |
10232 KB |
Output is correct |
40 |
Correct |
161 ms |
10208 KB |
Output is correct |
41 |
Correct |
191 ms |
10256 KB |
Output is correct |
42 |
Correct |
166 ms |
10216 KB |
Output is correct |
43 |
Correct |
84 ms |
10492 KB |
Output is correct |
44 |
Correct |
66 ms |
10316 KB |
Output is correct |
45 |
Correct |
148 ms |
13008 KB |
Output is correct |
46 |
Correct |
112 ms |
15944 KB |
Output is correct |
47 |
Correct |
221 ms |
15784 KB |
Output is correct |
48 |
Correct |
317 ms |
26980 KB |
Output is correct |
49 |
Correct |
326 ms |
25868 KB |
Output is correct |
50 |
Correct |
220 ms |
15684 KB |
Output is correct |
51 |
Correct |
223 ms |
15648 KB |
Output is correct |
52 |
Correct |
280 ms |
15712 KB |
Output is correct |
53 |
Correct |
246 ms |
14496 KB |
Output is correct |
54 |
Correct |
244 ms |
14520 KB |
Output is correct |
55 |
Correct |
12 ms |
5580 KB |
Output is correct |
56 |
Correct |
15 ms |
5424 KB |
Output is correct |
57 |
Correct |
95 ms |
10408 KB |
Output is correct |
58 |
Correct |
48 ms |
10500 KB |
Output is correct |
59 |
Correct |
126 ms |
16688 KB |
Output is correct |
60 |
Correct |
702 ms |
30228 KB |
Output is correct |
61 |
Correct |
281 ms |
15704 KB |
Output is correct |
62 |
Correct |
324 ms |
19524 KB |
Output is correct |
63 |
Correct |
439 ms |
19612 KB |
Output is correct |
64 |
Correct |
848 ms |
17460 KB |
Output is correct |
65 |
Correct |
322 ms |
15552 KB |
Output is correct |
66 |
Correct |
520 ms |
27776 KB |
Output is correct |
67 |
Correct |
187 ms |
19852 KB |
Output is correct |
68 |
Correct |
395 ms |
19740 KB |
Output is correct |
69 |
Correct |
358 ms |
19832 KB |
Output is correct |
70 |
Correct |
455 ms |
19328 KB |
Output is correct |