# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
166043 |
2019-11-30T11:53:03 Z |
errorgorn |
Race (IOI11_race) |
C++14 |
|
585 ms |
87600 KB |
#include "race.h"
#include <cstdio>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> ii;
vector<ii> al[200005];
int offset[200005];
int offset2[200005];
set<ii> rope[200005];
int ans=1000000;
int k;
void dfs(int i,int p){
rope[i].insert(ii(offset[i],offset2[i]));
int target;
set<ii>::iterator sit;
for (auto it:al[i]){
if (it.first==p) continue;
offset[it.first]=offset[i]+it.second;
offset2[it.first]=offset2[i]+1;
dfs(it.first,i);
if (rope[it.first].size()>rope[i].size()) swap(rope[it.first],rope[i]);
for (auto x:rope[it.first]){
target=k-x.first+offset[i]*2;
sit=rope[i].lower_bound(ii(target,-1));
if (sit==rope[i].end() || (*sit).first!=target) continue;
ans=min(ans,(*sit).second+x.second-offset2[i]*2);
}
rope[i].insert(rope[it.first].begin(),rope[it.first].end());
}
}
int best_path(int n, int K, int h[][2], int l[]){
k=K;
for (int x=0;x<n-1;x++){
al[h[x][0]].push_back(ii(h[x][1],l[x]));
al[h[x][1]].push_back(ii(h[x][0],l[x]));
}
dfs(0,-1);
return (ans==1000000)?-1:ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
14 ms |
14456 KB |
Output is correct |
4 |
Correct |
15 ms |
14456 KB |
Output is correct |
5 |
Correct |
14 ms |
14456 KB |
Output is correct |
6 |
Correct |
15 ms |
14456 KB |
Output is correct |
7 |
Correct |
15 ms |
14456 KB |
Output is correct |
8 |
Correct |
14 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14456 KB |
Output is correct |
10 |
Correct |
14 ms |
14456 KB |
Output is correct |
11 |
Correct |
14 ms |
14456 KB |
Output is correct |
12 |
Correct |
14 ms |
14456 KB |
Output is correct |
13 |
Correct |
14 ms |
14456 KB |
Output is correct |
14 |
Correct |
15 ms |
14456 KB |
Output is correct |
15 |
Correct |
14 ms |
14456 KB |
Output is correct |
16 |
Correct |
14 ms |
14456 KB |
Output is correct |
17 |
Correct |
16 ms |
14428 KB |
Output is correct |
18 |
Correct |
17 ms |
14456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
14 ms |
14456 KB |
Output is correct |
4 |
Correct |
15 ms |
14456 KB |
Output is correct |
5 |
Correct |
14 ms |
14456 KB |
Output is correct |
6 |
Correct |
15 ms |
14456 KB |
Output is correct |
7 |
Correct |
15 ms |
14456 KB |
Output is correct |
8 |
Correct |
14 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14456 KB |
Output is correct |
10 |
Correct |
14 ms |
14456 KB |
Output is correct |
11 |
Correct |
14 ms |
14456 KB |
Output is correct |
12 |
Correct |
14 ms |
14456 KB |
Output is correct |
13 |
Correct |
14 ms |
14456 KB |
Output is correct |
14 |
Correct |
15 ms |
14456 KB |
Output is correct |
15 |
Correct |
14 ms |
14456 KB |
Output is correct |
16 |
Correct |
14 ms |
14456 KB |
Output is correct |
17 |
Correct |
16 ms |
14428 KB |
Output is correct |
18 |
Correct |
17 ms |
14456 KB |
Output is correct |
19 |
Correct |
15 ms |
14456 KB |
Output is correct |
20 |
Correct |
14 ms |
14456 KB |
Output is correct |
21 |
Correct |
17 ms |
14712 KB |
Output is correct |
22 |
Correct |
17 ms |
14708 KB |
Output is correct |
23 |
Correct |
16 ms |
14712 KB |
Output is correct |
24 |
Correct |
15 ms |
14712 KB |
Output is correct |
25 |
Correct |
16 ms |
14712 KB |
Output is correct |
26 |
Correct |
17 ms |
14712 KB |
Output is correct |
27 |
Correct |
15 ms |
14584 KB |
Output is correct |
28 |
Correct |
16 ms |
14712 KB |
Output is correct |
29 |
Correct |
16 ms |
14712 KB |
Output is correct |
30 |
Correct |
16 ms |
14712 KB |
Output is correct |
31 |
Correct |
16 ms |
14712 KB |
Output is correct |
32 |
Correct |
15 ms |
14712 KB |
Output is correct |
33 |
Correct |
16 ms |
14712 KB |
Output is correct |
34 |
Correct |
16 ms |
14584 KB |
Output is correct |
35 |
Correct |
16 ms |
14584 KB |
Output is correct |
36 |
Correct |
15 ms |
14584 KB |
Output is correct |
37 |
Correct |
15 ms |
14584 KB |
Output is correct |
38 |
Correct |
16 ms |
14584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
14 ms |
14456 KB |
Output is correct |
4 |
Correct |
15 ms |
14456 KB |
Output is correct |
5 |
Correct |
14 ms |
14456 KB |
Output is correct |
6 |
Correct |
15 ms |
14456 KB |
Output is correct |
7 |
Correct |
15 ms |
14456 KB |
Output is correct |
8 |
Correct |
14 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14456 KB |
Output is correct |
10 |
Correct |
14 ms |
14456 KB |
Output is correct |
11 |
Correct |
14 ms |
14456 KB |
Output is correct |
12 |
Correct |
14 ms |
14456 KB |
Output is correct |
13 |
Correct |
14 ms |
14456 KB |
Output is correct |
14 |
Correct |
15 ms |
14456 KB |
Output is correct |
15 |
Correct |
14 ms |
14456 KB |
Output is correct |
16 |
Correct |
14 ms |
14456 KB |
Output is correct |
17 |
Correct |
16 ms |
14428 KB |
Output is correct |
18 |
Correct |
17 ms |
14456 KB |
Output is correct |
19 |
Correct |
196 ms |
36596 KB |
Output is correct |
20 |
Correct |
191 ms |
36472 KB |
Output is correct |
21 |
Correct |
189 ms |
36012 KB |
Output is correct |
22 |
Correct |
190 ms |
35012 KB |
Output is correct |
23 |
Correct |
243 ms |
45876 KB |
Output is correct |
24 |
Correct |
181 ms |
35832 KB |
Output is correct |
25 |
Correct |
187 ms |
38804 KB |
Output is correct |
26 |
Correct |
117 ms |
42548 KB |
Output is correct |
27 |
Correct |
288 ms |
43708 KB |
Output is correct |
28 |
Correct |
386 ms |
69492 KB |
Output is correct |
29 |
Correct |
387 ms |
68472 KB |
Output is correct |
30 |
Correct |
287 ms |
43696 KB |
Output is correct |
31 |
Correct |
298 ms |
43604 KB |
Output is correct |
32 |
Correct |
359 ms |
43580 KB |
Output is correct |
33 |
Correct |
326 ms |
44864 KB |
Output is correct |
34 |
Correct |
427 ms |
68704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
14 ms |
14456 KB |
Output is correct |
4 |
Correct |
15 ms |
14456 KB |
Output is correct |
5 |
Correct |
14 ms |
14456 KB |
Output is correct |
6 |
Correct |
15 ms |
14456 KB |
Output is correct |
7 |
Correct |
15 ms |
14456 KB |
Output is correct |
8 |
Correct |
14 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14456 KB |
Output is correct |
10 |
Correct |
14 ms |
14456 KB |
Output is correct |
11 |
Correct |
14 ms |
14456 KB |
Output is correct |
12 |
Correct |
14 ms |
14456 KB |
Output is correct |
13 |
Correct |
14 ms |
14456 KB |
Output is correct |
14 |
Correct |
15 ms |
14456 KB |
Output is correct |
15 |
Correct |
14 ms |
14456 KB |
Output is correct |
16 |
Correct |
14 ms |
14456 KB |
Output is correct |
17 |
Correct |
16 ms |
14428 KB |
Output is correct |
18 |
Correct |
17 ms |
14456 KB |
Output is correct |
19 |
Correct |
15 ms |
14456 KB |
Output is correct |
20 |
Correct |
14 ms |
14456 KB |
Output is correct |
21 |
Correct |
17 ms |
14712 KB |
Output is correct |
22 |
Correct |
17 ms |
14708 KB |
Output is correct |
23 |
Correct |
16 ms |
14712 KB |
Output is correct |
24 |
Correct |
15 ms |
14712 KB |
Output is correct |
25 |
Correct |
16 ms |
14712 KB |
Output is correct |
26 |
Correct |
17 ms |
14712 KB |
Output is correct |
27 |
Correct |
15 ms |
14584 KB |
Output is correct |
28 |
Correct |
16 ms |
14712 KB |
Output is correct |
29 |
Correct |
16 ms |
14712 KB |
Output is correct |
30 |
Correct |
16 ms |
14712 KB |
Output is correct |
31 |
Correct |
16 ms |
14712 KB |
Output is correct |
32 |
Correct |
15 ms |
14712 KB |
Output is correct |
33 |
Correct |
16 ms |
14712 KB |
Output is correct |
34 |
Correct |
16 ms |
14584 KB |
Output is correct |
35 |
Correct |
16 ms |
14584 KB |
Output is correct |
36 |
Correct |
15 ms |
14584 KB |
Output is correct |
37 |
Correct |
15 ms |
14584 KB |
Output is correct |
38 |
Correct |
16 ms |
14584 KB |
Output is correct |
39 |
Correct |
196 ms |
36596 KB |
Output is correct |
40 |
Correct |
191 ms |
36472 KB |
Output is correct |
41 |
Correct |
189 ms |
36012 KB |
Output is correct |
42 |
Correct |
190 ms |
35012 KB |
Output is correct |
43 |
Correct |
243 ms |
45876 KB |
Output is correct |
44 |
Correct |
181 ms |
35832 KB |
Output is correct |
45 |
Correct |
187 ms |
38804 KB |
Output is correct |
46 |
Correct |
117 ms |
42548 KB |
Output is correct |
47 |
Correct |
288 ms |
43708 KB |
Output is correct |
48 |
Correct |
386 ms |
69492 KB |
Output is correct |
49 |
Correct |
387 ms |
68472 KB |
Output is correct |
50 |
Correct |
287 ms |
43696 KB |
Output is correct |
51 |
Correct |
298 ms |
43604 KB |
Output is correct |
52 |
Correct |
359 ms |
43580 KB |
Output is correct |
53 |
Correct |
326 ms |
44864 KB |
Output is correct |
54 |
Correct |
427 ms |
68704 KB |
Output is correct |
55 |
Correct |
36 ms |
17144 KB |
Output is correct |
56 |
Correct |
25 ms |
16212 KB |
Output is correct |
57 |
Correct |
109 ms |
32780 KB |
Output is correct |
58 |
Correct |
69 ms |
26032 KB |
Output is correct |
59 |
Correct |
115 ms |
42872 KB |
Output is correct |
60 |
Correct |
335 ms |
68856 KB |
Output is correct |
61 |
Correct |
324 ms |
48120 KB |
Output is correct |
62 |
Correct |
271 ms |
44024 KB |
Output is correct |
63 |
Correct |
373 ms |
44112 KB |
Output is correct |
64 |
Correct |
582 ms |
87600 KB |
Output is correct |
65 |
Correct |
585 ms |
81224 KB |
Output is correct |
66 |
Correct |
415 ms |
66380 KB |
Output is correct |
67 |
Correct |
246 ms |
37704 KB |
Output is correct |
68 |
Correct |
541 ms |
55796 KB |
Output is correct |
69 |
Correct |
551 ms |
60048 KB |
Output is correct |
70 |
Correct |
472 ms |
54080 KB |
Output is correct |