# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
172450 |
2020-01-01T14:51:04 Z |
lobo_prix |
Race (IOI11_race) |
C++17 |
|
1735 ms |
59328 KB |
#include <bits/stdc++.h>
using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQ std::priority_queue
#ifndef DEBUG
#pragma GCC optimize ("Ofast")
auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif
template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
auto mapf(auto a, auto f){for(auto& x:a)x=f(x); return a;}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1);
#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;
const int N=200000;
int n,k;
Arr<pint> t[N];
int s[N];
int d[N];
int ct(int v, int sz_tot){
int mx=-1;
for(auto i:t[v])
if(!d[i.fi] and (mx<0 or s[mx]<s[i.fi]))
mx=i.fi;
if(mx<0 or s[mx]*2<=sz_tot)
return v;
d[v]++;
int ret=ct(mx, sz_tot);
d[v]--;
return ret;
}
int recalc(int v){
d[v]++;
s[v]=1;
for(auto i:t[v])
if(!d[i.fi])
s[v]+=recalc(i.fi);
d[v]--;
return s[v];
}
void get_paths(int v, int dist, int cnt, multiset<pint>& z){
z.insert({dist,cnt});
if(d[v])
return;
d[v]++;
for(auto i:t[v])
if(!d[i.fi])
get_paths(i.fi, dist+i.se, cnt+1, z);
d[v]--;
}
int f(int v){
recalc(v);
v=ct(v, s[v]);
d[v]++;
int ret=inf<int>();
multiset<pint> z;
z.insert({0,0});
for(auto i:t[v]){
multiset<pint> y;
if(!d[i.fi])
get_paths(i.fi, i.se, 1, y);
for(auto j:y){
auto it = z.lower_bound({k-j.fi,0});
if(it!=z.end() and it->fi==k-j.fi)
ret=min(ret, j.se+it->se);
}
z.insert(all(y));
}
for(auto i:t[v])
if(!d[i.fi])
ret=min(ret, f(i.fi));
//d[v]--;
return ret;
}
#include "race.h"
signed best_path(signed N, signed K, signed H[][2], signed L[])
{
n=N;k=K;
rep(i,n-1){
t[H[i][0]].push_back({H[i][1],L[i]});
t[H[i][1]].push_back({H[i][0],L[i]});
}
int ans=f(0);
return ans==inf<int>()?-1:ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
5112 KB |
Output is correct |
21 |
Correct |
8 ms |
5240 KB |
Output is correct |
22 |
Correct |
9 ms |
5240 KB |
Output is correct |
23 |
Correct |
9 ms |
5240 KB |
Output is correct |
24 |
Correct |
9 ms |
5368 KB |
Output is correct |
25 |
Correct |
9 ms |
5264 KB |
Output is correct |
26 |
Correct |
8 ms |
5240 KB |
Output is correct |
27 |
Correct |
8 ms |
5240 KB |
Output is correct |
28 |
Correct |
8 ms |
5244 KB |
Output is correct |
29 |
Correct |
8 ms |
5240 KB |
Output is correct |
30 |
Correct |
7 ms |
5368 KB |
Output is correct |
31 |
Correct |
9 ms |
5268 KB |
Output is correct |
32 |
Correct |
8 ms |
5240 KB |
Output is correct |
33 |
Correct |
9 ms |
5240 KB |
Output is correct |
34 |
Correct |
8 ms |
5240 KB |
Output is correct |
35 |
Correct |
7 ms |
5240 KB |
Output is correct |
36 |
Correct |
8 ms |
5240 KB |
Output is correct |
37 |
Correct |
8 ms |
5272 KB |
Output is correct |
38 |
Correct |
8 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
670 ms |
25504 KB |
Output is correct |
20 |
Correct |
659 ms |
25848 KB |
Output is correct |
21 |
Correct |
647 ms |
25796 KB |
Output is correct |
22 |
Correct |
553 ms |
25564 KB |
Output is correct |
23 |
Correct |
733 ms |
25336 KB |
Output is correct |
24 |
Correct |
339 ms |
21672 KB |
Output is correct |
25 |
Correct |
764 ms |
31864 KB |
Output is correct |
26 |
Correct |
516 ms |
31864 KB |
Output is correct |
27 |
Correct |
642 ms |
36128 KB |
Output is correct |
28 |
Correct |
1618 ms |
58248 KB |
Output is correct |
29 |
Correct |
1697 ms |
58232 KB |
Output is correct |
30 |
Correct |
585 ms |
36160 KB |
Output is correct |
31 |
Correct |
599 ms |
36088 KB |
Output is correct |
32 |
Correct |
694 ms |
36100 KB |
Output is correct |
33 |
Correct |
1520 ms |
46072 KB |
Output is correct |
34 |
Correct |
1668 ms |
44312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
5112 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
5112 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
5112 KB |
Output is correct |
21 |
Correct |
8 ms |
5240 KB |
Output is correct |
22 |
Correct |
9 ms |
5240 KB |
Output is correct |
23 |
Correct |
9 ms |
5240 KB |
Output is correct |
24 |
Correct |
9 ms |
5368 KB |
Output is correct |
25 |
Correct |
9 ms |
5264 KB |
Output is correct |
26 |
Correct |
8 ms |
5240 KB |
Output is correct |
27 |
Correct |
8 ms |
5240 KB |
Output is correct |
28 |
Correct |
8 ms |
5244 KB |
Output is correct |
29 |
Correct |
8 ms |
5240 KB |
Output is correct |
30 |
Correct |
7 ms |
5368 KB |
Output is correct |
31 |
Correct |
9 ms |
5268 KB |
Output is correct |
32 |
Correct |
8 ms |
5240 KB |
Output is correct |
33 |
Correct |
9 ms |
5240 KB |
Output is correct |
34 |
Correct |
8 ms |
5240 KB |
Output is correct |
35 |
Correct |
7 ms |
5240 KB |
Output is correct |
36 |
Correct |
8 ms |
5240 KB |
Output is correct |
37 |
Correct |
8 ms |
5272 KB |
Output is correct |
38 |
Correct |
8 ms |
5240 KB |
Output is correct |
39 |
Correct |
670 ms |
25504 KB |
Output is correct |
40 |
Correct |
659 ms |
25848 KB |
Output is correct |
41 |
Correct |
647 ms |
25796 KB |
Output is correct |
42 |
Correct |
553 ms |
25564 KB |
Output is correct |
43 |
Correct |
733 ms |
25336 KB |
Output is correct |
44 |
Correct |
339 ms |
21672 KB |
Output is correct |
45 |
Correct |
764 ms |
31864 KB |
Output is correct |
46 |
Correct |
516 ms |
31864 KB |
Output is correct |
47 |
Correct |
642 ms |
36128 KB |
Output is correct |
48 |
Correct |
1618 ms |
58248 KB |
Output is correct |
49 |
Correct |
1697 ms |
58232 KB |
Output is correct |
50 |
Correct |
585 ms |
36160 KB |
Output is correct |
51 |
Correct |
599 ms |
36088 KB |
Output is correct |
52 |
Correct |
694 ms |
36100 KB |
Output is correct |
53 |
Correct |
1520 ms |
46072 KB |
Output is correct |
54 |
Correct |
1668 ms |
44312 KB |
Output is correct |
55 |
Correct |
39 ms |
7160 KB |
Output is correct |
56 |
Correct |
41 ms |
7032 KB |
Output is correct |
57 |
Correct |
585 ms |
25132 KB |
Output is correct |
58 |
Correct |
128 ms |
19880 KB |
Output is correct |
59 |
Correct |
589 ms |
32068 KB |
Output is correct |
60 |
Correct |
1735 ms |
58976 KB |
Output is correct |
61 |
Correct |
607 ms |
36856 KB |
Output is correct |
62 |
Correct |
570 ms |
36856 KB |
Output is correct |
63 |
Correct |
700 ms |
36856 KB |
Output is correct |
64 |
Correct |
1599 ms |
48100 KB |
Output is correct |
65 |
Correct |
1228 ms |
46956 KB |
Output is correct |
66 |
Correct |
1691 ms |
59328 KB |
Output is correct |
67 |
Correct |
404 ms |
35928 KB |
Output is correct |
68 |
Correct |
749 ms |
42608 KB |
Output is correct |
69 |
Correct |
822 ms |
43008 KB |
Output is correct |
70 |
Correct |
729 ms |
40952 KB |
Output is correct |