# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011633 |
2024-07-01T00:06:20 Z |
LeonidCuk |
Race (IOI11_race) |
C++17 |
|
276 ms |
95056 KB |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>>g[200001];
vector<int>v(200001),sum(200001),sz(200001);
map<long long int,int>*m[200001];
int k,res=10000000;
void dfs(int a,int b,int dep,long long suma)
{
v[a]=dep;
sum[a]=suma;
sz[a]=1;
for(auto p:g[a])
{
if(p.first!=b)
{
dfs(p.first,a,dep+1,suma+p.second);
sz[a]+=sz[p.first];
}
}
}
void findres(int a,int b)
{
int bigc=-1,bigck=-1;
for(auto p:g[a])
{
if(p.first!=b)
{
if(sz[p.first]>bigck)
{
bigc=p.first;
bigck=sz[p.first];
}
findres(p.first,a);
}
}
if(bigc==-1)
{
m[a]= new map<long long int,int>();
}
else
{
m[a]=m[bigc];
}
(*m[a])[sum[a]]=v[a];
int t=2*sum[a]+k;
for(auto p:g[a])
{
if(p.first!=bigc&&p.first!=b)
{
for(auto it:*m[p.first])
{
if((*m[a]).find(t-it.first)!=(*m[a]).end())
{
res=min(res,it.second+(*m[a])[t-it.first]-2*v[a]);
}
}
for(auto it:*m[p.first])
{
if((*m[a]).find(it.first)==(*m[a]).end())
{
(*m[a])[it.first]=it.second;
}
else
{
(*m[a])[it.first]=min(it.second,(*m[a])[it.first]);
}
}
}
}
if((*m[a]).find(sum[a]+k)!=(*m[a]).end())
{
res=min(res,(*m[a])[sum[a]+k]-v[a]);
}
}
int best_path(int N,int K,int H[][2],int L[])
{
k=K;
for(int i=0;i<N-1;i++)
{
int a=H[i][0],b=H[i][1],c=L[i];
g[a].push_back({b,c});
g[b].push_back({a,c});
}
dfs(0,0,0,0);
findres(0,0);
if(res==10000000)
{
res=-1;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12632 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12632 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12888 KB |
Output is correct |
22 |
Correct |
3 ms |
12892 KB |
Output is correct |
23 |
Correct |
3 ms |
12900 KB |
Output is correct |
24 |
Correct |
3 ms |
12904 KB |
Output is correct |
25 |
Correct |
4 ms |
12904 KB |
Output is correct |
26 |
Correct |
3 ms |
12904 KB |
Output is correct |
27 |
Correct |
3 ms |
12648 KB |
Output is correct |
28 |
Correct |
4 ms |
12904 KB |
Output is correct |
29 |
Correct |
3 ms |
12904 KB |
Output is correct |
30 |
Correct |
4 ms |
12904 KB |
Output is correct |
31 |
Correct |
4 ms |
12904 KB |
Output is correct |
32 |
Correct |
3 ms |
12904 KB |
Output is correct |
33 |
Correct |
4 ms |
12904 KB |
Output is correct |
34 |
Correct |
4 ms |
12904 KB |
Output is correct |
35 |
Correct |
3 ms |
12904 KB |
Output is correct |
36 |
Correct |
4 ms |
12904 KB |
Output is correct |
37 |
Correct |
3 ms |
12648 KB |
Output is correct |
38 |
Correct |
3 ms |
12904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12632 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12636 KB |
Output is correct |
19 |
Correct |
66 ms |
32352 KB |
Output is correct |
20 |
Correct |
64 ms |
33228 KB |
Output is correct |
21 |
Correct |
73 ms |
33120 KB |
Output is correct |
22 |
Correct |
62 ms |
34396 KB |
Output is correct |
23 |
Correct |
93 ms |
47796 KB |
Output is correct |
24 |
Correct |
86 ms |
42592 KB |
Output is correct |
25 |
Correct |
48 ms |
30644 KB |
Output is correct |
26 |
Correct |
34 ms |
39004 KB |
Output is correct |
27 |
Correct |
120 ms |
43088 KB |
Output is correct |
28 |
Correct |
146 ms |
75872 KB |
Output is correct |
29 |
Correct |
144 ms |
74080 KB |
Output is correct |
30 |
Correct |
106 ms |
43616 KB |
Output is correct |
31 |
Correct |
126 ms |
43788 KB |
Output is correct |
32 |
Correct |
123 ms |
43468 KB |
Output is correct |
33 |
Correct |
114 ms |
36432 KB |
Output is correct |
34 |
Correct |
191 ms |
68804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12632 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12888 KB |
Output is correct |
22 |
Correct |
3 ms |
12892 KB |
Output is correct |
23 |
Correct |
3 ms |
12900 KB |
Output is correct |
24 |
Correct |
3 ms |
12904 KB |
Output is correct |
25 |
Correct |
4 ms |
12904 KB |
Output is correct |
26 |
Correct |
3 ms |
12904 KB |
Output is correct |
27 |
Correct |
3 ms |
12648 KB |
Output is correct |
28 |
Correct |
4 ms |
12904 KB |
Output is correct |
29 |
Correct |
3 ms |
12904 KB |
Output is correct |
30 |
Correct |
4 ms |
12904 KB |
Output is correct |
31 |
Correct |
4 ms |
12904 KB |
Output is correct |
32 |
Correct |
3 ms |
12904 KB |
Output is correct |
33 |
Correct |
4 ms |
12904 KB |
Output is correct |
34 |
Correct |
4 ms |
12904 KB |
Output is correct |
35 |
Correct |
3 ms |
12904 KB |
Output is correct |
36 |
Correct |
4 ms |
12904 KB |
Output is correct |
37 |
Correct |
3 ms |
12648 KB |
Output is correct |
38 |
Correct |
3 ms |
12904 KB |
Output is correct |
39 |
Correct |
66 ms |
32352 KB |
Output is correct |
40 |
Correct |
64 ms |
33228 KB |
Output is correct |
41 |
Correct |
73 ms |
33120 KB |
Output is correct |
42 |
Correct |
62 ms |
34396 KB |
Output is correct |
43 |
Correct |
93 ms |
47796 KB |
Output is correct |
44 |
Correct |
86 ms |
42592 KB |
Output is correct |
45 |
Correct |
48 ms |
30644 KB |
Output is correct |
46 |
Correct |
34 ms |
39004 KB |
Output is correct |
47 |
Correct |
120 ms |
43088 KB |
Output is correct |
48 |
Correct |
146 ms |
75872 KB |
Output is correct |
49 |
Correct |
144 ms |
74080 KB |
Output is correct |
50 |
Correct |
106 ms |
43616 KB |
Output is correct |
51 |
Correct |
126 ms |
43788 KB |
Output is correct |
52 |
Correct |
123 ms |
43468 KB |
Output is correct |
53 |
Correct |
114 ms |
36432 KB |
Output is correct |
54 |
Correct |
191 ms |
68804 KB |
Output is correct |
55 |
Correct |
12 ms |
15448 KB |
Output is correct |
56 |
Correct |
7 ms |
14172 KB |
Output is correct |
57 |
Correct |
38 ms |
31832 KB |
Output is correct |
58 |
Correct |
36 ms |
32208 KB |
Output is correct |
59 |
Correct |
53 ms |
45472 KB |
Output is correct |
60 |
Correct |
134 ms |
74884 KB |
Output is correct |
61 |
Correct |
138 ms |
46420 KB |
Output is correct |
62 |
Correct |
106 ms |
43436 KB |
Output is correct |
63 |
Correct |
117 ms |
43572 KB |
Output is correct |
64 |
Correct |
276 ms |
91472 KB |
Output is correct |
65 |
Correct |
276 ms |
95056 KB |
Output is correct |
66 |
Correct |
147 ms |
67408 KB |
Output is correct |
67 |
Correct |
89 ms |
50884 KB |
Output is correct |
68 |
Correct |
207 ms |
63892 KB |
Output is correct |
69 |
Correct |
187 ms |
62548 KB |
Output is correct |
70 |
Correct |
195 ms |
62220 KB |
Output is correct |