# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
217509 |
2020-03-30T04:27:07 Z |
Autoratch |
Race (IOI11_race) |
C++14 |
|
1795 ms |
52600 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
const int K = 19;
int n,k,cn;
vector<pair<int,int> > adj[N];
vector<int> cen[N];
int sz[N],pa[N],ans = INT_MAX;
bool blocked[N];
int dist[N];
map<int,int> res;
void dfs(int u,int p){ sz[u] = 1; for(auto [d,v] : adj[u]) if(v!=p and !blocked[v]) dfs(v,u),sz[u]+=sz[v]; }
void build(int u,int cp)
{
dfs(u,0);
int c = u,prev = 0;
while(true)
{
int mx = 0,id = 0;
for(auto [d,v] : adj[c]) if(!blocked[v] and v!=prev) if(sz[v]>mx) mx = sz[v],id = v;
if(mx*2>=sz[u]) prev = c,c = id;
else break;
}
if(cp==0) cn = c;
pa[c] = cp;
if(cp) cen[cp].push_back(c);
blocked[c] = true;
for(auto [d,v] : adj[c]) if(!blocked[v]) build(v,c);
}
void upd(int u,int p,bool f,int all,int len)
{
if(all>k) return;
if(!f)
{
if(all==k) ans = min(ans,len);
else if(res[k-all]) ans = min(ans,res[k-all]+len);
}
else if(res[all]==0 or res[all]>len) res[all] = len;
}
void sol(int c,int u,int p,int t,int w,int lv)
{
upd(u,c,t,w,lv);
for(auto [d,v] : adj[u]) if(!blocked[v] and v!=p) sol(c,v,u,t,w+d,lv+1);
}
void run(int u)
{
for(auto [d,v] : adj[u]) if(!blocked[v])
{
sol(u,v,u,0,d,1);
sol(u,v,u,1,d,1);
}
res.clear();
blocked[u] = true;
for(int v : cen[u]) run(v);
}
int best_path(int nn,int kk,int h[][2],int l[])
{
n = nn,k = kk;
for(int i = 0;i < n-1;i++)
{
int a = h[i][0],b = h[i][1],d = l[i]; a++,b++;
adj[a].push_back({d,b});
adj[b].push_back({d,a});
}
build(1,0);
fill(blocked,blocked+n+1,0);
run(cn);
if(ans==INT_MAX) ans = -1;
return ans;
}
Compilation message
race.cpp: In function 'void dfs(int, int)':
race.cpp:16:44: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
void dfs(int u,int p){ sz[u] = 1; for(auto [d,v] : adj[u]) if(v!=p and !blocked[v]) dfs(v,u),sz[u]+=sz[v]; }
^
race.cpp:16:48: warning: unused variable 'd' [-Wunused-variable]
void dfs(int u,int p){ sz[u] = 1; for(auto [d,v] : adj[u]) if(v!=p and !blocked[v]) dfs(v,u),sz[u]+=sz[v]; }
^
race.cpp: In function 'void build(int, int)':
race.cpp:25:18: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for(auto [d,v] : adj[c]) if(!blocked[v] and v!=prev) if(sz[v]>mx) mx = sz[v],id = v;
^
race.cpp:25:22: warning: unused variable 'd' [-Wunused-variable]
for(auto [d,v] : adj[c]) if(!blocked[v] and v!=prev) if(sz[v]>mx) mx = sz[v],id = v;
^
race.cpp:33:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for(auto [d,v] : adj[c]) if(!blocked[v]) build(v,c);
^
race.cpp:33:18: warning: unused variable 'd' [-Wunused-variable]
for(auto [d,v] : adj[c]) if(!blocked[v]) build(v,c);
^
race.cpp: In function 'void sol(int, int, int, int, int, int)':
race.cpp:50:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for(auto [d,v] : adj[u]) if(!blocked[v] and v!=p) sol(c,v,u,t,w+d,lv+1);
^
race.cpp: In function 'void run(int)':
race.cpp:55:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for(auto [d,v] : adj[u]) if(!blocked[v])
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
10 ms |
9600 KB |
Output is correct |
3 |
Correct |
10 ms |
9728 KB |
Output is correct |
4 |
Correct |
10 ms |
9728 KB |
Output is correct |
5 |
Correct |
13 ms |
9728 KB |
Output is correct |
6 |
Correct |
10 ms |
9728 KB |
Output is correct |
7 |
Correct |
10 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
9 |
Correct |
9 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
11 ms |
9776 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9776 KB |
Output is correct |
14 |
Correct |
11 ms |
9728 KB |
Output is correct |
15 |
Correct |
10 ms |
9728 KB |
Output is correct |
16 |
Correct |
11 ms |
9856 KB |
Output is correct |
17 |
Correct |
10 ms |
9728 KB |
Output is correct |
18 |
Correct |
10 ms |
9728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
10 ms |
9600 KB |
Output is correct |
3 |
Correct |
10 ms |
9728 KB |
Output is correct |
4 |
Correct |
10 ms |
9728 KB |
Output is correct |
5 |
Correct |
13 ms |
9728 KB |
Output is correct |
6 |
Correct |
10 ms |
9728 KB |
Output is correct |
7 |
Correct |
10 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
9 |
Correct |
9 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
11 ms |
9776 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9776 KB |
Output is correct |
14 |
Correct |
11 ms |
9728 KB |
Output is correct |
15 |
Correct |
10 ms |
9728 KB |
Output is correct |
16 |
Correct |
11 ms |
9856 KB |
Output is correct |
17 |
Correct |
10 ms |
9728 KB |
Output is correct |
18 |
Correct |
10 ms |
9728 KB |
Output is correct |
19 |
Correct |
10 ms |
9728 KB |
Output is correct |
20 |
Correct |
10 ms |
9728 KB |
Output is correct |
21 |
Correct |
12 ms |
9856 KB |
Output is correct |
22 |
Correct |
14 ms |
9856 KB |
Output is correct |
23 |
Correct |
11 ms |
9856 KB |
Output is correct |
24 |
Correct |
11 ms |
9856 KB |
Output is correct |
25 |
Correct |
12 ms |
9856 KB |
Output is correct |
26 |
Correct |
11 ms |
9856 KB |
Output is correct |
27 |
Correct |
11 ms |
9856 KB |
Output is correct |
28 |
Correct |
12 ms |
9856 KB |
Output is correct |
29 |
Correct |
12 ms |
9856 KB |
Output is correct |
30 |
Correct |
12 ms |
9856 KB |
Output is correct |
31 |
Correct |
12 ms |
9856 KB |
Output is correct |
32 |
Correct |
12 ms |
9856 KB |
Output is correct |
33 |
Correct |
13 ms |
9984 KB |
Output is correct |
34 |
Correct |
11 ms |
9856 KB |
Output is correct |
35 |
Correct |
12 ms |
9856 KB |
Output is correct |
36 |
Correct |
11 ms |
9856 KB |
Output is correct |
37 |
Correct |
12 ms |
9856 KB |
Output is correct |
38 |
Correct |
12 ms |
9856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
10 ms |
9600 KB |
Output is correct |
3 |
Correct |
10 ms |
9728 KB |
Output is correct |
4 |
Correct |
10 ms |
9728 KB |
Output is correct |
5 |
Correct |
13 ms |
9728 KB |
Output is correct |
6 |
Correct |
10 ms |
9728 KB |
Output is correct |
7 |
Correct |
10 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
9 |
Correct |
9 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
11 ms |
9776 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9776 KB |
Output is correct |
14 |
Correct |
11 ms |
9728 KB |
Output is correct |
15 |
Correct |
10 ms |
9728 KB |
Output is correct |
16 |
Correct |
11 ms |
9856 KB |
Output is correct |
17 |
Correct |
10 ms |
9728 KB |
Output is correct |
18 |
Correct |
10 ms |
9728 KB |
Output is correct |
19 |
Correct |
313 ms |
16888 KB |
Output is correct |
20 |
Correct |
312 ms |
16888 KB |
Output is correct |
21 |
Correct |
321 ms |
16888 KB |
Output is correct |
22 |
Correct |
309 ms |
17168 KB |
Output is correct |
23 |
Correct |
173 ms |
17272 KB |
Output is correct |
24 |
Correct |
132 ms |
16248 KB |
Output is correct |
25 |
Correct |
250 ms |
20984 KB |
Output is correct |
26 |
Correct |
144 ms |
23288 KB |
Output is correct |
27 |
Correct |
333 ms |
23800 KB |
Output is correct |
28 |
Correct |
594 ms |
36712 KB |
Output is correct |
29 |
Correct |
590 ms |
35832 KB |
Output is correct |
30 |
Correct |
332 ms |
23800 KB |
Output is correct |
31 |
Correct |
347 ms |
23928 KB |
Output is correct |
32 |
Correct |
425 ms |
23800 KB |
Output is correct |
33 |
Correct |
562 ms |
23928 KB |
Output is correct |
34 |
Correct |
387 ms |
23672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Correct |
10 ms |
9600 KB |
Output is correct |
3 |
Correct |
10 ms |
9728 KB |
Output is correct |
4 |
Correct |
10 ms |
9728 KB |
Output is correct |
5 |
Correct |
13 ms |
9728 KB |
Output is correct |
6 |
Correct |
10 ms |
9728 KB |
Output is correct |
7 |
Correct |
10 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
9 |
Correct |
9 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
11 ms |
9776 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
10 ms |
9776 KB |
Output is correct |
14 |
Correct |
11 ms |
9728 KB |
Output is correct |
15 |
Correct |
10 ms |
9728 KB |
Output is correct |
16 |
Correct |
11 ms |
9856 KB |
Output is correct |
17 |
Correct |
10 ms |
9728 KB |
Output is correct |
18 |
Correct |
10 ms |
9728 KB |
Output is correct |
19 |
Correct |
10 ms |
9728 KB |
Output is correct |
20 |
Correct |
10 ms |
9728 KB |
Output is correct |
21 |
Correct |
12 ms |
9856 KB |
Output is correct |
22 |
Correct |
14 ms |
9856 KB |
Output is correct |
23 |
Correct |
11 ms |
9856 KB |
Output is correct |
24 |
Correct |
11 ms |
9856 KB |
Output is correct |
25 |
Correct |
12 ms |
9856 KB |
Output is correct |
26 |
Correct |
11 ms |
9856 KB |
Output is correct |
27 |
Correct |
11 ms |
9856 KB |
Output is correct |
28 |
Correct |
12 ms |
9856 KB |
Output is correct |
29 |
Correct |
12 ms |
9856 KB |
Output is correct |
30 |
Correct |
12 ms |
9856 KB |
Output is correct |
31 |
Correct |
12 ms |
9856 KB |
Output is correct |
32 |
Correct |
12 ms |
9856 KB |
Output is correct |
33 |
Correct |
13 ms |
9984 KB |
Output is correct |
34 |
Correct |
11 ms |
9856 KB |
Output is correct |
35 |
Correct |
12 ms |
9856 KB |
Output is correct |
36 |
Correct |
11 ms |
9856 KB |
Output is correct |
37 |
Correct |
12 ms |
9856 KB |
Output is correct |
38 |
Correct |
12 ms |
9856 KB |
Output is correct |
39 |
Correct |
313 ms |
16888 KB |
Output is correct |
40 |
Correct |
312 ms |
16888 KB |
Output is correct |
41 |
Correct |
321 ms |
16888 KB |
Output is correct |
42 |
Correct |
309 ms |
17168 KB |
Output is correct |
43 |
Correct |
173 ms |
17272 KB |
Output is correct |
44 |
Correct |
132 ms |
16248 KB |
Output is correct |
45 |
Correct |
250 ms |
20984 KB |
Output is correct |
46 |
Correct |
144 ms |
23288 KB |
Output is correct |
47 |
Correct |
333 ms |
23800 KB |
Output is correct |
48 |
Correct |
594 ms |
36712 KB |
Output is correct |
49 |
Correct |
590 ms |
35832 KB |
Output is correct |
50 |
Correct |
332 ms |
23800 KB |
Output is correct |
51 |
Correct |
347 ms |
23928 KB |
Output is correct |
52 |
Correct |
425 ms |
23800 KB |
Output is correct |
53 |
Correct |
562 ms |
23928 KB |
Output is correct |
54 |
Correct |
387 ms |
23672 KB |
Output is correct |
55 |
Correct |
41 ms |
10624 KB |
Output is correct |
56 |
Correct |
29 ms |
10496 KB |
Output is correct |
57 |
Correct |
245 ms |
17272 KB |
Output is correct |
58 |
Correct |
59 ms |
16620 KB |
Output is correct |
59 |
Correct |
500 ms |
29944 KB |
Output is correct |
60 |
Correct |
1500 ms |
52600 KB |
Output is correct |
61 |
Correct |
447 ms |
24056 KB |
Output is correct |
62 |
Correct |
498 ms |
24312 KB |
Output is correct |
63 |
Correct |
577 ms |
24184 KB |
Output is correct |
64 |
Correct |
1795 ms |
33308 KB |
Output is correct |
65 |
Correct |
476 ms |
24184 KB |
Output is correct |
66 |
Correct |
1125 ms |
34168 KB |
Output is correct |
67 |
Correct |
168 ms |
23400 KB |
Output is correct |
68 |
Correct |
717 ms |
30824 KB |
Output is correct |
69 |
Correct |
722 ms |
30448 KB |
Output is correct |
70 |
Correct |
668 ms |
29944 KB |
Output is correct |