# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
603260 |
2022-07-23T19:29:04 Z |
MatijaL |
Race (IOI11_race) |
C++14 |
|
2909 ms |
93736 KB |
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define loop(i, a) FOR(i, 0, a-1)
typedef long long ll;
#define pll pair<ll, ll>
const ll maxn=300000;
set<ll> adj[maxn];
map<pll, ll> cost;
#define fs first
#define sc second
const bool DEBUG=0;
ll dist[maxn];
ll depth[maxn];
ll sz[maxn];
ll K;
ll best=1e9;
int dfs(ll u, ll p){
sz[u]=1;
for(auto e:adj[u]){
if(e==p)continue;
sz[u]+=dfs(e, u);
}
return sz[u];
}
set<pll> pre;
vector<pll> cur;
void dfs2(ll u, ll p, ll d){
dist[u]=d;
depth[u]=depth[p]+1;
if(d==K) best=min(best, depth[u]);
cur.pb(mp(d, depth[u]));
for(auto e:adj[u]){
if(e==p) continue;
dfs2(e, u, d+cost[mp(u, e)]);
}
}
ll centroid(ll u, ll p, ll N){
for(auto e : adj[u]){
if(e==p)continue;
if(sz[e]*2 > N) return centroid(e, u, N);
}
return u;
}
void decompose(ll v){
dfs(v, v);
ll c = centroid(v, v, sz[v]);
if(sz[v]==1) return;
//Prestej poti
vector<ll> rem(adj[c].begin(), adj[c].end());
pre.clear();
if(DEBUG) printf("Decomposing on %lld\n", c);
for(auto e : rem){
depth[c]=0;
dfs2(e, c, cost[mp(c, e)]);
if(DEBUG)printf("child %lld\n", e);
for(auto p : cur){
if(p.fs>K) continue;
if(DEBUG)printf("path %lld %lld\n", p.fs, p.sc);
auto b_p = pre.lower_bound(mp(K-p.fs, 0));
if(b_p==pre.end()) continue;
auto b = *b_p;
if(b.fs+p.fs==K) {
if(p.sc+b.sc<best){
//printf("centroid %d found %d+%d | %d - %d\n", c, p.fs, b.fs, p.sc, b.sc);
best=min(best, p.sc+b.sc);
}
}
}
for(auto _e : cur)pre.insert(_e);
cur.clear();
}
//Rekurzivno razstavi
for(auto e : rem){
adj[c].erase(e);adj[e].erase(c);
decompose(e);
}
}
int best_path(int N, int _K, int H[][2], int L[]){
FOR(i, 0, N-2){
ll a=H[i][0], b=H[i][1];
adj[a].insert(b);adj[b].insert(a);
cost[mp(a,b)]=L[i];cost[mp(b, a)]=L[i];
}
K=_K;
decompose(0);
if(best==1e9)return -1;
return best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
10 ms |
14420 KB |
Output is correct |
3 |
Correct |
10 ms |
14448 KB |
Output is correct |
4 |
Correct |
9 ms |
14432 KB |
Output is correct |
5 |
Correct |
8 ms |
14436 KB |
Output is correct |
6 |
Correct |
8 ms |
14420 KB |
Output is correct |
7 |
Correct |
9 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14420 KB |
Output is correct |
9 |
Correct |
8 ms |
14432 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
8 ms |
14420 KB |
Output is correct |
12 |
Correct |
7 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14420 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
9 ms |
14420 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
9 ms |
14420 KB |
Output is correct |
18 |
Correct |
9 ms |
14340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
10 ms |
14420 KB |
Output is correct |
3 |
Correct |
10 ms |
14448 KB |
Output is correct |
4 |
Correct |
9 ms |
14432 KB |
Output is correct |
5 |
Correct |
8 ms |
14436 KB |
Output is correct |
6 |
Correct |
8 ms |
14420 KB |
Output is correct |
7 |
Correct |
9 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14420 KB |
Output is correct |
9 |
Correct |
8 ms |
14432 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
8 ms |
14420 KB |
Output is correct |
12 |
Correct |
7 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14420 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
9 ms |
14420 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
9 ms |
14420 KB |
Output is correct |
18 |
Correct |
9 ms |
14340 KB |
Output is correct |
19 |
Correct |
8 ms |
14420 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
9 ms |
14676 KB |
Output is correct |
22 |
Correct |
10 ms |
14704 KB |
Output is correct |
23 |
Correct |
10 ms |
14756 KB |
Output is correct |
24 |
Correct |
9 ms |
14752 KB |
Output is correct |
25 |
Correct |
10 ms |
14760 KB |
Output is correct |
26 |
Correct |
9 ms |
14680 KB |
Output is correct |
27 |
Correct |
10 ms |
14676 KB |
Output is correct |
28 |
Correct |
10 ms |
14756 KB |
Output is correct |
29 |
Correct |
12 ms |
14700 KB |
Output is correct |
30 |
Correct |
11 ms |
14756 KB |
Output is correct |
31 |
Correct |
10 ms |
14680 KB |
Output is correct |
32 |
Correct |
10 ms |
14676 KB |
Output is correct |
33 |
Correct |
10 ms |
14748 KB |
Output is correct |
34 |
Correct |
10 ms |
14676 KB |
Output is correct |
35 |
Correct |
10 ms |
14676 KB |
Output is correct |
36 |
Correct |
9 ms |
14676 KB |
Output is correct |
37 |
Correct |
10 ms |
14704 KB |
Output is correct |
38 |
Correct |
9 ms |
14676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
10 ms |
14420 KB |
Output is correct |
3 |
Correct |
10 ms |
14448 KB |
Output is correct |
4 |
Correct |
9 ms |
14432 KB |
Output is correct |
5 |
Correct |
8 ms |
14436 KB |
Output is correct |
6 |
Correct |
8 ms |
14420 KB |
Output is correct |
7 |
Correct |
9 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14420 KB |
Output is correct |
9 |
Correct |
8 ms |
14432 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
8 ms |
14420 KB |
Output is correct |
12 |
Correct |
7 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14420 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
9 ms |
14420 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
9 ms |
14420 KB |
Output is correct |
18 |
Correct |
9 ms |
14340 KB |
Output is correct |
19 |
Correct |
683 ms |
40960 KB |
Output is correct |
20 |
Correct |
605 ms |
40964 KB |
Output is correct |
21 |
Correct |
662 ms |
40944 KB |
Output is correct |
22 |
Correct |
677 ms |
41032 KB |
Output is correct |
23 |
Correct |
771 ms |
40904 KB |
Output is correct |
24 |
Correct |
371 ms |
40528 KB |
Output is correct |
25 |
Correct |
1146 ms |
52420 KB |
Output is correct |
26 |
Correct |
441 ms |
53476 KB |
Output is correct |
27 |
Correct |
698 ms |
71240 KB |
Output is correct |
28 |
Correct |
2877 ms |
93364 KB |
Output is correct |
29 |
Correct |
2736 ms |
93492 KB |
Output is correct |
30 |
Correct |
755 ms |
71272 KB |
Output is correct |
31 |
Correct |
704 ms |
71260 KB |
Output is correct |
32 |
Correct |
1188 ms |
71164 KB |
Output is correct |
33 |
Correct |
1871 ms |
70344 KB |
Output is correct |
34 |
Correct |
2274 ms |
82576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
10 ms |
14420 KB |
Output is correct |
3 |
Correct |
10 ms |
14448 KB |
Output is correct |
4 |
Correct |
9 ms |
14432 KB |
Output is correct |
5 |
Correct |
8 ms |
14436 KB |
Output is correct |
6 |
Correct |
8 ms |
14420 KB |
Output is correct |
7 |
Correct |
9 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14420 KB |
Output is correct |
9 |
Correct |
8 ms |
14432 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
8 ms |
14420 KB |
Output is correct |
12 |
Correct |
7 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14420 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
9 ms |
14420 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
9 ms |
14420 KB |
Output is correct |
18 |
Correct |
9 ms |
14340 KB |
Output is correct |
19 |
Correct |
8 ms |
14420 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
9 ms |
14676 KB |
Output is correct |
22 |
Correct |
10 ms |
14704 KB |
Output is correct |
23 |
Correct |
10 ms |
14756 KB |
Output is correct |
24 |
Correct |
9 ms |
14752 KB |
Output is correct |
25 |
Correct |
10 ms |
14760 KB |
Output is correct |
26 |
Correct |
9 ms |
14680 KB |
Output is correct |
27 |
Correct |
10 ms |
14676 KB |
Output is correct |
28 |
Correct |
10 ms |
14756 KB |
Output is correct |
29 |
Correct |
12 ms |
14700 KB |
Output is correct |
30 |
Correct |
11 ms |
14756 KB |
Output is correct |
31 |
Correct |
10 ms |
14680 KB |
Output is correct |
32 |
Correct |
10 ms |
14676 KB |
Output is correct |
33 |
Correct |
10 ms |
14748 KB |
Output is correct |
34 |
Correct |
10 ms |
14676 KB |
Output is correct |
35 |
Correct |
10 ms |
14676 KB |
Output is correct |
36 |
Correct |
9 ms |
14676 KB |
Output is correct |
37 |
Correct |
10 ms |
14704 KB |
Output is correct |
38 |
Correct |
9 ms |
14676 KB |
Output is correct |
39 |
Correct |
683 ms |
40960 KB |
Output is correct |
40 |
Correct |
605 ms |
40964 KB |
Output is correct |
41 |
Correct |
662 ms |
40944 KB |
Output is correct |
42 |
Correct |
677 ms |
41032 KB |
Output is correct |
43 |
Correct |
771 ms |
40904 KB |
Output is correct |
44 |
Correct |
371 ms |
40528 KB |
Output is correct |
45 |
Correct |
1146 ms |
52420 KB |
Output is correct |
46 |
Correct |
441 ms |
53476 KB |
Output is correct |
47 |
Correct |
698 ms |
71240 KB |
Output is correct |
48 |
Correct |
2877 ms |
93364 KB |
Output is correct |
49 |
Correct |
2736 ms |
93492 KB |
Output is correct |
50 |
Correct |
755 ms |
71272 KB |
Output is correct |
51 |
Correct |
704 ms |
71260 KB |
Output is correct |
52 |
Correct |
1188 ms |
71164 KB |
Output is correct |
53 |
Correct |
1871 ms |
70344 KB |
Output is correct |
54 |
Correct |
2274 ms |
82576 KB |
Output is correct |
55 |
Correct |
45 ms |
17632 KB |
Output is correct |
56 |
Correct |
37 ms |
17196 KB |
Output is correct |
57 |
Correct |
356 ms |
41772 KB |
Output is correct |
58 |
Correct |
171 ms |
41648 KB |
Output is correct |
59 |
Correct |
500 ms |
53808 KB |
Output is correct |
60 |
Correct |
2742 ms |
93240 KB |
Output is correct |
61 |
Correct |
745 ms |
75288 KB |
Output is correct |
62 |
Correct |
662 ms |
71396 KB |
Output is correct |
63 |
Correct |
1091 ms |
71396 KB |
Output is correct |
64 |
Correct |
2149 ms |
81688 KB |
Output is correct |
65 |
Correct |
1782 ms |
82964 KB |
Output is correct |
66 |
Correct |
2909 ms |
93736 KB |
Output is correct |
67 |
Correct |
572 ms |
70260 KB |
Output is correct |
68 |
Correct |
1232 ms |
81476 KB |
Output is correct |
69 |
Correct |
1274 ms |
82368 KB |
Output is correct |
70 |
Correct |
1164 ms |
78460 KB |
Output is correct |