# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
42565 |
2018-02-28T06:22:49 Z |
comfile |
Race (IOI11_race) |
C++14 |
|
2879 ms |
42984 KB |
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long int ll;
using namespace std;
const int N = 200010;
int n,k,sz[N],dead[N],ans;
vector<pii> g[N];
void get_sz(int cur,int prev){
sz[cur] = 1;
for(auto &x : g[cur]) if(!dead[x.first] && x.first!=prev){
get_sz(x.first,cur);
sz[cur] += sz[x.first];
}
}
int dfs(int cur,int prev,int tot){
for(auto &x : g[cur]) if(!dead[x.first] && x.first!=prev){
if(sz[x.first]>(tot/2)) return dfs(x.first,cur,tot);
}
return cur;
}
int one(int start){
get_sz(start,-1);
return dfs(start,-1,sz[start]);
}
void rec(int cur){
int c = one(cur);
dead[c] = 1;
for(auto &x : g[c]) if(!dead[x.first]) rec(x.first);
map<int,int> cnt;
function<void (int,int,int,int)> dfs3 = [&](int cu,int prv,int st,int _depth){
if(_depth>k) return;
cnt[_depth] = cnt[_depth]?min(cnt[_depth],st):st;
for(auto &x : g[cu]) if(!dead[x.first] && x.first!=prv)
dfs3(x.first,cu,st+1,_depth+x.second);
};
function<void (int,int,int,int)> dfs4 = [&](int cu,int prv,int st,int _depth){
if(_depth>k) return;
if(cnt[k-_depth]) ans = min(ans,st+cnt[k-_depth]);
for(auto &x : g[cu]) if(!dead[x.first] && x.first!=prv)
dfs4(x.first,cu,st+1,_depth+x.second);
};
dfs3(c,-1,0,0);
if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
for(auto &x : g[c]) if(!dead[x.first]){
dfs4(x.first,c,1,x.second);
dfs3(x.first,c,1,x.second);
}
dead[c] = 0;
}
int best_path(int _n,int _k,int h[][2],int l[]){
ans = 1e9;
n = _n; k = _k;
for(int i=0;i<n-1;i++){
int a = h[i][0];
int b = h[i][1];
int c = l[i];
g[a].pb(mp(b,c));
g[b].pb(mp(a,c));
}
rec(0);
if(ans>=1e9) ans = -1;
return ans;
}
Compilation message
race.cpp: In function 'void rec(int)':
race.cpp:45:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
^~
race.cpp:45:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
7 ms |
5240 KB |
Output is correct |
4 |
Correct |
6 ms |
5264 KB |
Output is correct |
5 |
Correct |
6 ms |
5264 KB |
Output is correct |
6 |
Correct |
8 ms |
5264 KB |
Output is correct |
7 |
Correct |
6 ms |
5264 KB |
Output is correct |
8 |
Correct |
6 ms |
5264 KB |
Output is correct |
9 |
Correct |
8 ms |
5264 KB |
Output is correct |
10 |
Correct |
8 ms |
5264 KB |
Output is correct |
11 |
Correct |
7 ms |
5304 KB |
Output is correct |
12 |
Correct |
7 ms |
5308 KB |
Output is correct |
13 |
Correct |
7 ms |
5308 KB |
Output is correct |
14 |
Correct |
8 ms |
5308 KB |
Output is correct |
15 |
Correct |
6 ms |
5308 KB |
Output is correct |
16 |
Correct |
7 ms |
5308 KB |
Output is correct |
17 |
Correct |
6 ms |
5308 KB |
Output is correct |
18 |
Correct |
7 ms |
5308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
7 ms |
5240 KB |
Output is correct |
4 |
Correct |
6 ms |
5264 KB |
Output is correct |
5 |
Correct |
6 ms |
5264 KB |
Output is correct |
6 |
Correct |
8 ms |
5264 KB |
Output is correct |
7 |
Correct |
6 ms |
5264 KB |
Output is correct |
8 |
Correct |
6 ms |
5264 KB |
Output is correct |
9 |
Correct |
8 ms |
5264 KB |
Output is correct |
10 |
Correct |
8 ms |
5264 KB |
Output is correct |
11 |
Correct |
7 ms |
5304 KB |
Output is correct |
12 |
Correct |
7 ms |
5308 KB |
Output is correct |
13 |
Correct |
7 ms |
5308 KB |
Output is correct |
14 |
Correct |
8 ms |
5308 KB |
Output is correct |
15 |
Correct |
6 ms |
5308 KB |
Output is correct |
16 |
Correct |
7 ms |
5308 KB |
Output is correct |
17 |
Correct |
6 ms |
5308 KB |
Output is correct |
18 |
Correct |
7 ms |
5308 KB |
Output is correct |
19 |
Correct |
7 ms |
5308 KB |
Output is correct |
20 |
Correct |
7 ms |
5308 KB |
Output is correct |
21 |
Correct |
9 ms |
5328 KB |
Output is correct |
22 |
Correct |
8 ms |
5372 KB |
Output is correct |
23 |
Correct |
9 ms |
5372 KB |
Output is correct |
24 |
Correct |
10 ms |
5372 KB |
Output is correct |
25 |
Correct |
10 ms |
5500 KB |
Output is correct |
26 |
Correct |
7 ms |
5500 KB |
Output is correct |
27 |
Correct |
6 ms |
5500 KB |
Output is correct |
28 |
Correct |
9 ms |
5500 KB |
Output is correct |
29 |
Correct |
9 ms |
5500 KB |
Output is correct |
30 |
Correct |
9 ms |
5500 KB |
Output is correct |
31 |
Correct |
11 ms |
5500 KB |
Output is correct |
32 |
Correct |
10 ms |
5500 KB |
Output is correct |
33 |
Correct |
11 ms |
5500 KB |
Output is correct |
34 |
Correct |
8 ms |
5500 KB |
Output is correct |
35 |
Correct |
8 ms |
5500 KB |
Output is correct |
36 |
Correct |
10 ms |
5500 KB |
Output is correct |
37 |
Correct |
8 ms |
5500 KB |
Output is correct |
38 |
Correct |
9 ms |
5500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
7 ms |
5240 KB |
Output is correct |
4 |
Correct |
6 ms |
5264 KB |
Output is correct |
5 |
Correct |
6 ms |
5264 KB |
Output is correct |
6 |
Correct |
8 ms |
5264 KB |
Output is correct |
7 |
Correct |
6 ms |
5264 KB |
Output is correct |
8 |
Correct |
6 ms |
5264 KB |
Output is correct |
9 |
Correct |
8 ms |
5264 KB |
Output is correct |
10 |
Correct |
8 ms |
5264 KB |
Output is correct |
11 |
Correct |
7 ms |
5304 KB |
Output is correct |
12 |
Correct |
7 ms |
5308 KB |
Output is correct |
13 |
Correct |
7 ms |
5308 KB |
Output is correct |
14 |
Correct |
8 ms |
5308 KB |
Output is correct |
15 |
Correct |
6 ms |
5308 KB |
Output is correct |
16 |
Correct |
7 ms |
5308 KB |
Output is correct |
17 |
Correct |
6 ms |
5308 KB |
Output is correct |
18 |
Correct |
7 ms |
5308 KB |
Output is correct |
19 |
Correct |
461 ms |
10968 KB |
Output is correct |
20 |
Correct |
498 ms |
10968 KB |
Output is correct |
21 |
Correct |
482 ms |
10968 KB |
Output is correct |
22 |
Correct |
549 ms |
11132 KB |
Output is correct |
23 |
Correct |
201 ms |
11260 KB |
Output is correct |
24 |
Correct |
169 ms |
11260 KB |
Output is correct |
25 |
Correct |
387 ms |
12908 KB |
Output is correct |
26 |
Correct |
235 ms |
15996 KB |
Output is correct |
27 |
Correct |
458 ms |
16784 KB |
Output is correct |
28 |
Correct |
520 ms |
24828 KB |
Output is correct |
29 |
Correct |
591 ms |
24828 KB |
Output is correct |
30 |
Correct |
481 ms |
24828 KB |
Output is correct |
31 |
Correct |
470 ms |
24828 KB |
Output is correct |
32 |
Correct |
504 ms |
24828 KB |
Output is correct |
33 |
Correct |
841 ms |
24828 KB |
Output is correct |
34 |
Correct |
399 ms |
24828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
5 ms |
5112 KB |
Output is correct |
3 |
Correct |
7 ms |
5240 KB |
Output is correct |
4 |
Correct |
6 ms |
5264 KB |
Output is correct |
5 |
Correct |
6 ms |
5264 KB |
Output is correct |
6 |
Correct |
8 ms |
5264 KB |
Output is correct |
7 |
Correct |
6 ms |
5264 KB |
Output is correct |
8 |
Correct |
6 ms |
5264 KB |
Output is correct |
9 |
Correct |
8 ms |
5264 KB |
Output is correct |
10 |
Correct |
8 ms |
5264 KB |
Output is correct |
11 |
Correct |
7 ms |
5304 KB |
Output is correct |
12 |
Correct |
7 ms |
5308 KB |
Output is correct |
13 |
Correct |
7 ms |
5308 KB |
Output is correct |
14 |
Correct |
8 ms |
5308 KB |
Output is correct |
15 |
Correct |
6 ms |
5308 KB |
Output is correct |
16 |
Correct |
7 ms |
5308 KB |
Output is correct |
17 |
Correct |
6 ms |
5308 KB |
Output is correct |
18 |
Correct |
7 ms |
5308 KB |
Output is correct |
19 |
Correct |
7 ms |
5308 KB |
Output is correct |
20 |
Correct |
7 ms |
5308 KB |
Output is correct |
21 |
Correct |
9 ms |
5328 KB |
Output is correct |
22 |
Correct |
8 ms |
5372 KB |
Output is correct |
23 |
Correct |
9 ms |
5372 KB |
Output is correct |
24 |
Correct |
10 ms |
5372 KB |
Output is correct |
25 |
Correct |
10 ms |
5500 KB |
Output is correct |
26 |
Correct |
7 ms |
5500 KB |
Output is correct |
27 |
Correct |
6 ms |
5500 KB |
Output is correct |
28 |
Correct |
9 ms |
5500 KB |
Output is correct |
29 |
Correct |
9 ms |
5500 KB |
Output is correct |
30 |
Correct |
9 ms |
5500 KB |
Output is correct |
31 |
Correct |
11 ms |
5500 KB |
Output is correct |
32 |
Correct |
10 ms |
5500 KB |
Output is correct |
33 |
Correct |
11 ms |
5500 KB |
Output is correct |
34 |
Correct |
8 ms |
5500 KB |
Output is correct |
35 |
Correct |
8 ms |
5500 KB |
Output is correct |
36 |
Correct |
10 ms |
5500 KB |
Output is correct |
37 |
Correct |
8 ms |
5500 KB |
Output is correct |
38 |
Correct |
9 ms |
5500 KB |
Output is correct |
39 |
Correct |
461 ms |
10968 KB |
Output is correct |
40 |
Correct |
498 ms |
10968 KB |
Output is correct |
41 |
Correct |
482 ms |
10968 KB |
Output is correct |
42 |
Correct |
549 ms |
11132 KB |
Output is correct |
43 |
Correct |
201 ms |
11260 KB |
Output is correct |
44 |
Correct |
169 ms |
11260 KB |
Output is correct |
45 |
Correct |
387 ms |
12908 KB |
Output is correct |
46 |
Correct |
235 ms |
15996 KB |
Output is correct |
47 |
Correct |
458 ms |
16784 KB |
Output is correct |
48 |
Correct |
520 ms |
24828 KB |
Output is correct |
49 |
Correct |
591 ms |
24828 KB |
Output is correct |
50 |
Correct |
481 ms |
24828 KB |
Output is correct |
51 |
Correct |
470 ms |
24828 KB |
Output is correct |
52 |
Correct |
504 ms |
24828 KB |
Output is correct |
53 |
Correct |
841 ms |
24828 KB |
Output is correct |
54 |
Correct |
399 ms |
24828 KB |
Output is correct |
55 |
Correct |
73 ms |
24828 KB |
Output is correct |
56 |
Correct |
39 ms |
24828 KB |
Output is correct |
57 |
Correct |
365 ms |
24828 KB |
Output is correct |
58 |
Correct |
101 ms |
24828 KB |
Output is correct |
59 |
Correct |
985 ms |
24828 KB |
Output is correct |
60 |
Correct |
2867 ms |
42984 KB |
Output is correct |
61 |
Correct |
643 ms |
42984 KB |
Output is correct |
62 |
Correct |
924 ms |
42984 KB |
Output is correct |
63 |
Correct |
832 ms |
42984 KB |
Output is correct |
64 |
Correct |
2879 ms |
42984 KB |
Output is correct |
65 |
Correct |
284 ms |
42984 KB |
Output is correct |
66 |
Correct |
1598 ms |
42984 KB |
Output is correct |
67 |
Correct |
260 ms |
42984 KB |
Output is correct |
68 |
Correct |
1002 ms |
42984 KB |
Output is correct |
69 |
Correct |
1008 ms |
42984 KB |
Output is correct |
70 |
Correct |
938 ms |
42984 KB |
Output is correct |