# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
402470 |
2021-05-11T18:22:59 Z |
Jasiekstrz |
Race (IOI11_race) |
C++17 |
|
1829 ms |
56388 KB |
#include<bits/stdc++.h>
#include "race.h"
#define fi first
#define se second
using namespace std;
const int NN=2e5;
const int INF=1e9+7;
struct Poss
{
int val[2],g[2];
Poss()
{
val[0]=val[1]=INF;
g[0]=g[1]=0;
}
void operator+=(pair<int,int> oth)
{
int vv=oth.fi,gg=oth.se;
if(vv<val[0] && g[0]!=gg)
{
val[1]=val[0];
g[1]=g[0];
val[0]=vv;
g[0]=gg;
}
else if(vv<val[0])
val[0]=vv;
else if(vv<val[1] && g[0]!=gg)
{
val[1]=vv;
g[1]=gg;
}
return;
}
int get(int x)
{
return (x==g[0] ? val[1]:val[0]);
}
};
int k;
vector<pair<int,int>> e[NN+10];
bool vis[NN+10];
int siz[NN+10];
map<int,Poss> mp;
void dfs_siz(int x,int p)
{
siz[x]=1;
for(auto v:e[x])
{
if(!vis[v.fi] && v.fi!=p)
{
dfs_siz(v.fi,x);
siz[x]+=siz[v.fi];
}
}
return;
}
int centro(int x,int p,int s_all)
{
for(auto v:e[x])
{
if(vis[v.fi] || v.fi==p)
continue;
int c=centro(v.fi,x,s_all);
if(c!=-1)
return c;
}
if(2*siz[x]>=s_all)
return x;
return -1;
}
int dfs(int x,int p,int d1,int d2,int id)
{
int ans=INF;
ans=min(ans,d2+mp[k-d1].get(id));
mp[d1]+=make_pair(d2,id);
for(auto v:e[x])
{
if(vis[v.fi] || v.fi==p)
continue;
ans=min(ans,dfs(v.fi,x,min(INF,d1+v.se),d2+1,id));
}
return ans;
}
int solve(int x)
{
int ans=INF;
dfs_siz(x,-1);
x=centro(x,-1,siz[x]);
vis[x]=true;
mp.clear();
mp[0]+=make_pair(0,x);
for(auto v:e[x])
{
if(!vis[v.fi])
ans=min(ans,dfs(v.fi,x,v.se,1,v.fi));
}
for(auto v:e[x])
{
if(!vis[v.fi])
ans=min(ans,solve(v.fi));
}
return ans;
}
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]});
}
int ans=solve(0);
return (ans>=INF ? -1:ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 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 |
3 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 |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4972 KB |
Output is correct |
14 |
Correct |
4 ms |
5024 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 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 |
3 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 |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4972 KB |
Output is correct |
14 |
Correct |
4 ms |
5024 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
5 ms |
5008 KB |
Output is correct |
22 |
Correct |
6 ms |
5140 KB |
Output is correct |
23 |
Correct |
6 ms |
5196 KB |
Output is correct |
24 |
Correct |
6 ms |
5196 KB |
Output is correct |
25 |
Correct |
5 ms |
5196 KB |
Output is correct |
26 |
Correct |
5 ms |
5196 KB |
Output is correct |
27 |
Correct |
5 ms |
5068 KB |
Output is correct |
28 |
Correct |
6 ms |
5140 KB |
Output is correct |
29 |
Correct |
6 ms |
5140 KB |
Output is correct |
30 |
Correct |
6 ms |
5196 KB |
Output is correct |
31 |
Correct |
6 ms |
5196 KB |
Output is correct |
32 |
Correct |
6 ms |
5192 KB |
Output is correct |
33 |
Correct |
6 ms |
5196 KB |
Output is correct |
34 |
Correct |
7 ms |
5196 KB |
Output is correct |
35 |
Correct |
7 ms |
5196 KB |
Output is correct |
36 |
Correct |
6 ms |
5196 KB |
Output is correct |
37 |
Correct |
5 ms |
5188 KB |
Output is correct |
38 |
Correct |
6 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 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 |
3 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 |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4972 KB |
Output is correct |
14 |
Correct |
4 ms |
5024 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
283 ms |
11692 KB |
Output is correct |
20 |
Correct |
277 ms |
11584 KB |
Output is correct |
21 |
Correct |
277 ms |
11700 KB |
Output is correct |
22 |
Correct |
236 ms |
11792 KB |
Output is correct |
23 |
Correct |
384 ms |
12076 KB |
Output is correct |
24 |
Correct |
172 ms |
11800 KB |
Output is correct |
25 |
Correct |
254 ms |
17992 KB |
Output is correct |
26 |
Correct |
115 ms |
18936 KB |
Output is correct |
27 |
Correct |
432 ms |
17732 KB |
Output is correct |
28 |
Correct |
1778 ms |
56388 KB |
Output is correct |
29 |
Correct |
1746 ms |
55288 KB |
Output is correct |
30 |
Correct |
404 ms |
17612 KB |
Output is correct |
31 |
Correct |
397 ms |
17728 KB |
Output is correct |
32 |
Correct |
523 ms |
17712 KB |
Output is correct |
33 |
Correct |
574 ms |
16468 KB |
Output is correct |
34 |
Correct |
1632 ms |
40864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 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 |
3 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 |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4972 KB |
Output is correct |
14 |
Correct |
4 ms |
5024 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
4 ms |
4940 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
5 ms |
5008 KB |
Output is correct |
22 |
Correct |
6 ms |
5140 KB |
Output is correct |
23 |
Correct |
6 ms |
5196 KB |
Output is correct |
24 |
Correct |
6 ms |
5196 KB |
Output is correct |
25 |
Correct |
5 ms |
5196 KB |
Output is correct |
26 |
Correct |
5 ms |
5196 KB |
Output is correct |
27 |
Correct |
5 ms |
5068 KB |
Output is correct |
28 |
Correct |
6 ms |
5140 KB |
Output is correct |
29 |
Correct |
6 ms |
5140 KB |
Output is correct |
30 |
Correct |
6 ms |
5196 KB |
Output is correct |
31 |
Correct |
6 ms |
5196 KB |
Output is correct |
32 |
Correct |
6 ms |
5192 KB |
Output is correct |
33 |
Correct |
6 ms |
5196 KB |
Output is correct |
34 |
Correct |
7 ms |
5196 KB |
Output is correct |
35 |
Correct |
7 ms |
5196 KB |
Output is correct |
36 |
Correct |
6 ms |
5196 KB |
Output is correct |
37 |
Correct |
5 ms |
5188 KB |
Output is correct |
38 |
Correct |
6 ms |
5196 KB |
Output is correct |
39 |
Correct |
283 ms |
11692 KB |
Output is correct |
40 |
Correct |
277 ms |
11584 KB |
Output is correct |
41 |
Correct |
277 ms |
11700 KB |
Output is correct |
42 |
Correct |
236 ms |
11792 KB |
Output is correct |
43 |
Correct |
384 ms |
12076 KB |
Output is correct |
44 |
Correct |
172 ms |
11800 KB |
Output is correct |
45 |
Correct |
254 ms |
17992 KB |
Output is correct |
46 |
Correct |
115 ms |
18936 KB |
Output is correct |
47 |
Correct |
432 ms |
17732 KB |
Output is correct |
48 |
Correct |
1778 ms |
56388 KB |
Output is correct |
49 |
Correct |
1746 ms |
55288 KB |
Output is correct |
50 |
Correct |
404 ms |
17612 KB |
Output is correct |
51 |
Correct |
397 ms |
17728 KB |
Output is correct |
52 |
Correct |
523 ms |
17712 KB |
Output is correct |
53 |
Correct |
574 ms |
16468 KB |
Output is correct |
54 |
Correct |
1632 ms |
40864 KB |
Output is correct |
55 |
Correct |
40 ms |
6304 KB |
Output is correct |
56 |
Correct |
21 ms |
5660 KB |
Output is correct |
57 |
Correct |
172 ms |
11980 KB |
Output is correct |
58 |
Correct |
51 ms |
11532 KB |
Output is correct |
59 |
Correct |
492 ms |
27772 KB |
Output is correct |
60 |
Correct |
1680 ms |
52628 KB |
Output is correct |
61 |
Correct |
496 ms |
20708 KB |
Output is correct |
62 |
Correct |
397 ms |
17680 KB |
Output is correct |
63 |
Correct |
505 ms |
17708 KB |
Output is correct |
64 |
Correct |
1690 ms |
29132 KB |
Output is correct |
65 |
Correct |
1540 ms |
41864 KB |
Output is correct |
66 |
Correct |
1829 ms |
53444 KB |
Output is correct |
67 |
Correct |
165 ms |
17656 KB |
Output is correct |
68 |
Correct |
802 ms |
38660 KB |
Output is correct |
69 |
Correct |
832 ms |
38872 KB |
Output is correct |
70 |
Correct |
789 ms |
37124 KB |
Output is correct |