# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
360134 |
2021-01-27T14:12:36 Z |
Sho10 |
Race (IOI11_race) |
C++17 |
|
1291 ms |
136328 KB |
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#include "race.h"
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll ans=LINF,k;
vector<pair<ll,ll>>g[200005];
map<ll,ll>d,dist;
set<pair<ll,ll>>s[200005];
void dfs(ll node,ll par){
s[node].insert(mp(dist[node],d[node]));
for(auto it : g[node]){
if(it.f==par){
continue;
}
dist[it.f]=dist[node]+it.s;
d[it.f]=d[node]+1;
dfs(it.f,node);
if(s[node].size()<s[it.f].size()){
swap(s[node],s[it.f]);
}
for(auto it1 : s[it.f]){
auto pos=s[node].lower_bound(mp(k-it1.f+2*dist[node],0ll));
if(pos!=s[node].end()&&pos->f+it1.f-2*dist[node]==k){
//cout<<it1.s<<' '<<pos->s<<' '<<2*d[node]<<endl;
ans=min(ans,it1.s+pos->s-2*d[node]);
}
}
for(auto it1 : s[it.f]){
s[node].insert(it1);
}
}
}
int best_path(int n,int K,int h[][2],int l[]){
for(ll i=0;i<n-1;i++)
{
g[h[i][0]].pb(mp(h[i][1],l[i]));
g[h[i][1]].pb(mp(h[i][0],l[i]));
}
k=K;
dfs(0,-1);
if(ans==LINF){
ans=-1;
}
return ans;
}
/*
int32_t main(){
CODE_START;
int a[5][2];
a[0][0]=0;
a[0][1]=1;
a[1][0]=0;
a[1][1]=2;
int nr[4];
nr[0]=1;
nr[1]=2;
nr[2]=4;
cout<<best_path(3,3,a,nr)<<endl;
}
* */
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
9 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14572 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14592 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
9 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14572 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14592 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
9 ms |
14444 KB |
Output is correct |
20 |
Correct |
10 ms |
14456 KB |
Output is correct |
21 |
Correct |
13 ms |
14828 KB |
Output is correct |
22 |
Correct |
12 ms |
14848 KB |
Output is correct |
23 |
Correct |
12 ms |
14828 KB |
Output is correct |
24 |
Correct |
12 ms |
14828 KB |
Output is correct |
25 |
Correct |
11 ms |
14828 KB |
Output is correct |
26 |
Correct |
12 ms |
14828 KB |
Output is correct |
27 |
Correct |
13 ms |
14844 KB |
Output is correct |
28 |
Correct |
12 ms |
14828 KB |
Output is correct |
29 |
Correct |
13 ms |
14828 KB |
Output is correct |
30 |
Correct |
12 ms |
14828 KB |
Output is correct |
31 |
Correct |
11 ms |
14828 KB |
Output is correct |
32 |
Correct |
12 ms |
14828 KB |
Output is correct |
33 |
Correct |
12 ms |
14956 KB |
Output is correct |
34 |
Correct |
12 ms |
14828 KB |
Output is correct |
35 |
Correct |
11 ms |
14828 KB |
Output is correct |
36 |
Correct |
11 ms |
14828 KB |
Output is correct |
37 |
Correct |
11 ms |
14828 KB |
Output is correct |
38 |
Correct |
13 ms |
14956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
9 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14572 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14592 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
414 ms |
55020 KB |
Output is correct |
20 |
Correct |
390 ms |
54984 KB |
Output is correct |
21 |
Correct |
391 ms |
54400 KB |
Output is correct |
22 |
Correct |
394 ms |
52972 KB |
Output is correct |
23 |
Correct |
447 ms |
67524 KB |
Output is correct |
24 |
Correct |
403 ms |
53492 KB |
Output is correct |
25 |
Correct |
441 ms |
60416 KB |
Output is correct |
26 |
Correct |
222 ms |
67052 KB |
Output is correct |
27 |
Correct |
498 ms |
77720 KB |
Output is correct |
28 |
Correct |
928 ms |
120044 KB |
Output is correct |
29 |
Correct |
938 ms |
117944 KB |
Output is correct |
30 |
Correct |
482 ms |
77804 KB |
Output is correct |
31 |
Correct |
489 ms |
77548 KB |
Output is correct |
32 |
Correct |
877 ms |
77676 KB |
Output is correct |
33 |
Correct |
794 ms |
79472 KB |
Output is correct |
34 |
Correct |
972 ms |
112620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
9 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14572 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
11 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
10 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
10 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14592 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
9 ms |
14444 KB |
Output is correct |
20 |
Correct |
10 ms |
14456 KB |
Output is correct |
21 |
Correct |
13 ms |
14828 KB |
Output is correct |
22 |
Correct |
12 ms |
14848 KB |
Output is correct |
23 |
Correct |
12 ms |
14828 KB |
Output is correct |
24 |
Correct |
12 ms |
14828 KB |
Output is correct |
25 |
Correct |
11 ms |
14828 KB |
Output is correct |
26 |
Correct |
12 ms |
14828 KB |
Output is correct |
27 |
Correct |
13 ms |
14844 KB |
Output is correct |
28 |
Correct |
12 ms |
14828 KB |
Output is correct |
29 |
Correct |
13 ms |
14828 KB |
Output is correct |
30 |
Correct |
12 ms |
14828 KB |
Output is correct |
31 |
Correct |
11 ms |
14828 KB |
Output is correct |
32 |
Correct |
12 ms |
14828 KB |
Output is correct |
33 |
Correct |
12 ms |
14956 KB |
Output is correct |
34 |
Correct |
12 ms |
14828 KB |
Output is correct |
35 |
Correct |
11 ms |
14828 KB |
Output is correct |
36 |
Correct |
11 ms |
14828 KB |
Output is correct |
37 |
Correct |
11 ms |
14828 KB |
Output is correct |
38 |
Correct |
13 ms |
14956 KB |
Output is correct |
39 |
Correct |
414 ms |
55020 KB |
Output is correct |
40 |
Correct |
390 ms |
54984 KB |
Output is correct |
41 |
Correct |
391 ms |
54400 KB |
Output is correct |
42 |
Correct |
394 ms |
52972 KB |
Output is correct |
43 |
Correct |
447 ms |
67524 KB |
Output is correct |
44 |
Correct |
403 ms |
53492 KB |
Output is correct |
45 |
Correct |
441 ms |
60416 KB |
Output is correct |
46 |
Correct |
222 ms |
67052 KB |
Output is correct |
47 |
Correct |
498 ms |
77720 KB |
Output is correct |
48 |
Correct |
928 ms |
120044 KB |
Output is correct |
49 |
Correct |
938 ms |
117944 KB |
Output is correct |
50 |
Correct |
482 ms |
77804 KB |
Output is correct |
51 |
Correct |
489 ms |
77548 KB |
Output is correct |
52 |
Correct |
877 ms |
77676 KB |
Output is correct |
53 |
Correct |
794 ms |
79472 KB |
Output is correct |
54 |
Correct |
972 ms |
112620 KB |
Output is correct |
55 |
Correct |
39 ms |
19308 KB |
Output is correct |
56 |
Correct |
33 ms |
18028 KB |
Output is correct |
57 |
Correct |
207 ms |
49916 KB |
Output is correct |
58 |
Correct |
168 ms |
40156 KB |
Output is correct |
59 |
Correct |
216 ms |
67052 KB |
Output is correct |
60 |
Correct |
894 ms |
118508 KB |
Output is correct |
61 |
Correct |
528 ms |
83512 KB |
Output is correct |
62 |
Correct |
467 ms |
77676 KB |
Output is correct |
63 |
Correct |
866 ms |
77640 KB |
Output is correct |
64 |
Correct |
1022 ms |
136328 KB |
Output is correct |
65 |
Correct |
1076 ms |
127668 KB |
Output is correct |
66 |
Correct |
974 ms |
113280 KB |
Output is correct |
67 |
Correct |
639 ms |
67540 KB |
Output is correct |
68 |
Correct |
1040 ms |
92132 KB |
Output is correct |
69 |
Correct |
1291 ms |
97752 KB |
Output is correct |
70 |
Correct |
956 ms |
88676 KB |
Output is correct |