# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
725920 |
2023-04-18T08:50:51 Z |
sofija6 |
Race (IOI11_race) |
C++14 |
|
481 ms |
37512 KB |
#include <bits/stdc++.h>
#include "race.h"
#define MAXN 200010
#define MAXK 1000010
using namespace std;
vector<pair<int,int> > G[MAXN];
bool check[MAXN];
int subtree[MAXN],k,res=INT_MAX;
pair<int,int> ans[MAXK];
void DFS_Subtree(int i,int p)
{
subtree[i]=1;
for (auto next : G[i])
{
if (next.first!=p && !check[next.first])
{
DFS_Subtree(next.first,i);
subtree[i]+=subtree[next.first];
}
}
}
int DFS_Centroid(int i,int p,int root)
{
for (auto next : G[i])
{
if (next.first!=p && !check[next.first] && subtree[next.first]>subtree[root]/2)
return DFS_Centroid(next.first,i,root);
}
return i;
}
int c;
void DFS_Paths(int i,int p,int d,int cnt)
{
if (d>k)
return;
if ((ans[k-d].first && ans[k-d].second==c) || k==d)
res=min(res,ans[k-d].first+cnt);
for (auto next : G[i])
{
if (next.first!=p && !check[next.first])
DFS_Paths(next.first,i,d+next.second,cnt+1);
}
}
void DFS_Fill(int i,int p,int d,int cnt)
{
if (d>k)
return;
if (d && (!ans[d].first || ans[d].second!=c || ans[d].first>cnt))
ans[d]={cnt,c};
for (auto next : G[i])
{
if (next.first!=p && !check[next.first])
DFS_Fill(next.first,i,d+next.second,cnt+1);
}
}
void Solve(int i)
{
DFS_Subtree(i,i);
c=DFS_Centroid(i,i,i);
check[c]=true;
for (auto next : G[c])
{
if (check[next.first])
continue;
DFS_Paths(next.first,c,next.second,1);
DFS_Fill(next.first,c,next.second,1);
}
for (auto next : G[c])
{
if (!check[next.first])
Solve(next.first);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
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]});
}
Solve(0);
return (res==INT_MAX?-1 : res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5008 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5004 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5000 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5008 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5004 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5000 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5004 KB |
Output is correct |
19 |
Correct |
3 ms |
5008 KB |
Output is correct |
20 |
Correct |
3 ms |
5000 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
5 ms |
8404 KB |
Output is correct |
23 |
Correct |
5 ms |
7952 KB |
Output is correct |
24 |
Correct |
6 ms |
9112 KB |
Output is correct |
25 |
Correct |
6 ms |
8276 KB |
Output is correct |
26 |
Correct |
5 ms |
7380 KB |
Output is correct |
27 |
Correct |
3 ms |
5012 KB |
Output is correct |
28 |
Correct |
6 ms |
6612 KB |
Output is correct |
29 |
Correct |
5 ms |
7508 KB |
Output is correct |
30 |
Correct |
5 ms |
7764 KB |
Output is correct |
31 |
Correct |
5 ms |
8404 KB |
Output is correct |
32 |
Correct |
6 ms |
8404 KB |
Output is correct |
33 |
Correct |
7 ms |
9812 KB |
Output is correct |
34 |
Correct |
6 ms |
9044 KB |
Output is correct |
35 |
Correct |
7 ms |
10012 KB |
Output is correct |
36 |
Correct |
7 ms |
10324 KB |
Output is correct |
37 |
Correct |
5 ms |
8276 KB |
Output is correct |
38 |
Correct |
5 ms |
7252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5008 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5004 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5000 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5004 KB |
Output is correct |
19 |
Correct |
111 ms |
10444 KB |
Output is correct |
20 |
Correct |
118 ms |
10352 KB |
Output is correct |
21 |
Correct |
125 ms |
10396 KB |
Output is correct |
22 |
Correct |
127 ms |
10464 KB |
Output is correct |
23 |
Correct |
66 ms |
10724 KB |
Output is correct |
24 |
Correct |
54 ms |
10500 KB |
Output is correct |
25 |
Correct |
114 ms |
14116 KB |
Output is correct |
26 |
Correct |
80 ms |
17736 KB |
Output is correct |
27 |
Correct |
155 ms |
16064 KB |
Output is correct |
28 |
Correct |
257 ms |
30292 KB |
Output is correct |
29 |
Correct |
229 ms |
29164 KB |
Output is correct |
30 |
Correct |
157 ms |
16108 KB |
Output is correct |
31 |
Correct |
153 ms |
16000 KB |
Output is correct |
32 |
Correct |
176 ms |
15972 KB |
Output is correct |
33 |
Correct |
169 ms |
14836 KB |
Output is correct |
34 |
Correct |
195 ms |
14884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5008 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5004 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5000 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5004 KB |
Output is correct |
19 |
Correct |
3 ms |
5008 KB |
Output is correct |
20 |
Correct |
3 ms |
5000 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
5 ms |
8404 KB |
Output is correct |
23 |
Correct |
5 ms |
7952 KB |
Output is correct |
24 |
Correct |
6 ms |
9112 KB |
Output is correct |
25 |
Correct |
6 ms |
8276 KB |
Output is correct |
26 |
Correct |
5 ms |
7380 KB |
Output is correct |
27 |
Correct |
3 ms |
5012 KB |
Output is correct |
28 |
Correct |
6 ms |
6612 KB |
Output is correct |
29 |
Correct |
5 ms |
7508 KB |
Output is correct |
30 |
Correct |
5 ms |
7764 KB |
Output is correct |
31 |
Correct |
5 ms |
8404 KB |
Output is correct |
32 |
Correct |
6 ms |
8404 KB |
Output is correct |
33 |
Correct |
7 ms |
9812 KB |
Output is correct |
34 |
Correct |
6 ms |
9044 KB |
Output is correct |
35 |
Correct |
7 ms |
10012 KB |
Output is correct |
36 |
Correct |
7 ms |
10324 KB |
Output is correct |
37 |
Correct |
5 ms |
8276 KB |
Output is correct |
38 |
Correct |
5 ms |
7252 KB |
Output is correct |
39 |
Correct |
111 ms |
10444 KB |
Output is correct |
40 |
Correct |
118 ms |
10352 KB |
Output is correct |
41 |
Correct |
125 ms |
10396 KB |
Output is correct |
42 |
Correct |
127 ms |
10464 KB |
Output is correct |
43 |
Correct |
66 ms |
10724 KB |
Output is correct |
44 |
Correct |
54 ms |
10500 KB |
Output is correct |
45 |
Correct |
114 ms |
14116 KB |
Output is correct |
46 |
Correct |
80 ms |
17736 KB |
Output is correct |
47 |
Correct |
155 ms |
16064 KB |
Output is correct |
48 |
Correct |
257 ms |
30292 KB |
Output is correct |
49 |
Correct |
229 ms |
29164 KB |
Output is correct |
50 |
Correct |
157 ms |
16108 KB |
Output is correct |
51 |
Correct |
153 ms |
16000 KB |
Output is correct |
52 |
Correct |
176 ms |
15972 KB |
Output is correct |
53 |
Correct |
169 ms |
14836 KB |
Output is correct |
54 |
Correct |
195 ms |
14884 KB |
Output is correct |
55 |
Correct |
11 ms |
5648 KB |
Output is correct |
56 |
Correct |
11 ms |
5588 KB |
Output is correct |
57 |
Correct |
73 ms |
10700 KB |
Output is correct |
58 |
Correct |
33 ms |
10816 KB |
Output is correct |
59 |
Correct |
88 ms |
19660 KB |
Output is correct |
60 |
Correct |
474 ms |
37132 KB |
Output is correct |
61 |
Correct |
181 ms |
18892 KB |
Output is correct |
62 |
Correct |
215 ms |
18812 KB |
Output is correct |
63 |
Correct |
260 ms |
18916 KB |
Output is correct |
64 |
Correct |
481 ms |
21288 KB |
Output is correct |
65 |
Correct |
236 ms |
19624 KB |
Output is correct |
66 |
Correct |
370 ms |
37512 KB |
Output is correct |
67 |
Correct |
108 ms |
19488 KB |
Output is correct |
68 |
Correct |
239 ms |
24884 KB |
Output is correct |
69 |
Correct |
235 ms |
25152 KB |
Output is correct |
70 |
Correct |
220 ms |
24268 KB |
Output is correct |