# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484190 |
2021-11-02T10:51:46 Z |
FEDIKUS |
Race (IOI11_race) |
C++17 |
|
396 ms |
78268 KB |
#include "race.h"
#include<bits/stdc++.h>
#define xx first
#define yy second
using namespace std;
const int maxn=2e5+10;
vector<pair<int,int> > g[maxn];
pair<pair<int,int> ,map<int,int> > s[maxn];
int merges(pair<pair<int,int> ,map<int,int> > &a,pair<pair<int,int> ,map<int,int> > &b,int c,int k){
b.xx.xx+=c;
b.xx.yy+=1;
if(a.yy.size()<b.yy.size()) swap(a,b);
int ret=INT_MAX;
for(auto &i:b.yy){
if(a.yy.find(k-i.xx-b.xx.xx-a.xx.xx)!=a.yy.end())
ret=min(ret,a.yy[k-i.xx-b.xx.xx-a.xx.xx]+a.xx.yy+i.yy+b.xx.yy);
}
for(auto &i:b.yy){
if(a.yy.find(i.xx+b.xx.xx-a.xx.xx)!=a.yy.end())
a.yy[i.xx+b.xx.xx-a.xx.xx]=min(a.yy[i.xx+b.xx.xx-a.xx.xx],i.yy+b.xx.yy-a.xx.yy);
else
a.yy[i.xx+b.xx.xx-a.xx.xx]=i.yy+b.xx.yy-a.xx.yy;
}
return ret;
}
int dfs(int cvor,int k,int p=-1){
int ret=INT_MAX;
for(pair<int,int> i:g[cvor]){
if(i.xx==p) continue;
ret=min(ret,dfs(i.xx,k,cvor));
ret=min(ret,merges(s[cvor],s[i.xx],i.yy,k));
}
s[cvor].yy[-s[cvor].xx.xx]=-s[cvor].xx.yy;
if(s[cvor].yy.find(k-s[cvor].xx.xx)!=s[cvor].yy.end())
ret=min(ret,s[cvor].yy[k-s[cvor].xx.xx]+s[cvor].xx.yy);
return ret;
}
int best_path(int n, int k, int h[][2], int l[]){
for(int i=0;i<n-1;i++){
g[h[i][0]].push_back(make_pair(h[i][1],l[i]));
g[h[i][1]].push_back(make_pair(h[i][0],l[i]));
}
int ret=dfs(0,k);
return ret==INT_MAX ? -1:ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16076 KB |
Output is correct |
2 |
Correct |
8 ms |
15948 KB |
Output is correct |
3 |
Correct |
8 ms |
15872 KB |
Output is correct |
4 |
Correct |
7 ms |
15948 KB |
Output is correct |
5 |
Correct |
7 ms |
15968 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
7 ms |
15964 KB |
Output is correct |
10 |
Correct |
8 ms |
15964 KB |
Output is correct |
11 |
Correct |
8 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15880 KB |
Output is correct |
14 |
Correct |
7 ms |
15968 KB |
Output is correct |
15 |
Correct |
7 ms |
15960 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15956 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16076 KB |
Output is correct |
2 |
Correct |
8 ms |
15948 KB |
Output is correct |
3 |
Correct |
8 ms |
15872 KB |
Output is correct |
4 |
Correct |
7 ms |
15948 KB |
Output is correct |
5 |
Correct |
7 ms |
15968 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
7 ms |
15964 KB |
Output is correct |
10 |
Correct |
8 ms |
15964 KB |
Output is correct |
11 |
Correct |
8 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15880 KB |
Output is correct |
14 |
Correct |
7 ms |
15968 KB |
Output is correct |
15 |
Correct |
7 ms |
15960 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15956 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
19 |
Correct |
8 ms |
15904 KB |
Output is correct |
20 |
Correct |
8 ms |
15948 KB |
Output is correct |
21 |
Correct |
8 ms |
16096 KB |
Output is correct |
22 |
Correct |
9 ms |
16100 KB |
Output is correct |
23 |
Correct |
9 ms |
16076 KB |
Output is correct |
24 |
Correct |
8 ms |
16076 KB |
Output is correct |
25 |
Correct |
8 ms |
16096 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
8 ms |
16076 KB |
Output is correct |
28 |
Correct |
9 ms |
16128 KB |
Output is correct |
29 |
Correct |
9 ms |
16076 KB |
Output is correct |
30 |
Correct |
9 ms |
16076 KB |
Output is correct |
31 |
Correct |
9 ms |
16076 KB |
Output is correct |
32 |
Correct |
8 ms |
16076 KB |
Output is correct |
33 |
Correct |
8 ms |
16176 KB |
Output is correct |
34 |
Correct |
8 ms |
16076 KB |
Output is correct |
35 |
Correct |
8 ms |
16076 KB |
Output is correct |
36 |
Correct |
8 ms |
16076 KB |
Output is correct |
37 |
Correct |
8 ms |
16076 KB |
Output is correct |
38 |
Correct |
11 ms |
16108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16076 KB |
Output is correct |
2 |
Correct |
8 ms |
15948 KB |
Output is correct |
3 |
Correct |
8 ms |
15872 KB |
Output is correct |
4 |
Correct |
7 ms |
15948 KB |
Output is correct |
5 |
Correct |
7 ms |
15968 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
7 ms |
15964 KB |
Output is correct |
10 |
Correct |
8 ms |
15964 KB |
Output is correct |
11 |
Correct |
8 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15880 KB |
Output is correct |
14 |
Correct |
7 ms |
15968 KB |
Output is correct |
15 |
Correct |
7 ms |
15960 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15956 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
19 |
Correct |
100 ms |
30560 KB |
Output is correct |
20 |
Correct |
98 ms |
30556 KB |
Output is correct |
21 |
Correct |
98 ms |
30532 KB |
Output is correct |
22 |
Correct |
98 ms |
30660 KB |
Output is correct |
23 |
Correct |
140 ms |
40648 KB |
Output is correct |
24 |
Correct |
113 ms |
35268 KB |
Output is correct |
25 |
Correct |
63 ms |
29536 KB |
Output is correct |
26 |
Correct |
48 ms |
35588 KB |
Output is correct |
27 |
Correct |
164 ms |
38296 KB |
Output is correct |
28 |
Correct |
189 ms |
65016 KB |
Output is correct |
29 |
Correct |
184 ms |
63644 KB |
Output is correct |
30 |
Correct |
164 ms |
38400 KB |
Output is correct |
31 |
Correct |
173 ms |
38408 KB |
Output is correct |
32 |
Correct |
204 ms |
38548 KB |
Output is correct |
33 |
Correct |
177 ms |
37092 KB |
Output is correct |
34 |
Correct |
272 ms |
62068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16076 KB |
Output is correct |
2 |
Correct |
8 ms |
15948 KB |
Output is correct |
3 |
Correct |
8 ms |
15872 KB |
Output is correct |
4 |
Correct |
7 ms |
15948 KB |
Output is correct |
5 |
Correct |
7 ms |
15968 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
8 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
7 ms |
15964 KB |
Output is correct |
10 |
Correct |
8 ms |
15964 KB |
Output is correct |
11 |
Correct |
8 ms |
15948 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
7 ms |
15880 KB |
Output is correct |
14 |
Correct |
7 ms |
15968 KB |
Output is correct |
15 |
Correct |
7 ms |
15960 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
7 ms |
15956 KB |
Output is correct |
18 |
Correct |
8 ms |
15948 KB |
Output is correct |
19 |
Correct |
8 ms |
15904 KB |
Output is correct |
20 |
Correct |
8 ms |
15948 KB |
Output is correct |
21 |
Correct |
8 ms |
16096 KB |
Output is correct |
22 |
Correct |
9 ms |
16100 KB |
Output is correct |
23 |
Correct |
9 ms |
16076 KB |
Output is correct |
24 |
Correct |
8 ms |
16076 KB |
Output is correct |
25 |
Correct |
8 ms |
16096 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
8 ms |
16076 KB |
Output is correct |
28 |
Correct |
9 ms |
16128 KB |
Output is correct |
29 |
Correct |
9 ms |
16076 KB |
Output is correct |
30 |
Correct |
9 ms |
16076 KB |
Output is correct |
31 |
Correct |
9 ms |
16076 KB |
Output is correct |
32 |
Correct |
8 ms |
16076 KB |
Output is correct |
33 |
Correct |
8 ms |
16176 KB |
Output is correct |
34 |
Correct |
8 ms |
16076 KB |
Output is correct |
35 |
Correct |
8 ms |
16076 KB |
Output is correct |
36 |
Correct |
8 ms |
16076 KB |
Output is correct |
37 |
Correct |
8 ms |
16076 KB |
Output is correct |
38 |
Correct |
11 ms |
16108 KB |
Output is correct |
39 |
Correct |
100 ms |
30560 KB |
Output is correct |
40 |
Correct |
98 ms |
30556 KB |
Output is correct |
41 |
Correct |
98 ms |
30532 KB |
Output is correct |
42 |
Correct |
98 ms |
30660 KB |
Output is correct |
43 |
Correct |
140 ms |
40648 KB |
Output is correct |
44 |
Correct |
113 ms |
35268 KB |
Output is correct |
45 |
Correct |
63 ms |
29536 KB |
Output is correct |
46 |
Correct |
48 ms |
35588 KB |
Output is correct |
47 |
Correct |
164 ms |
38296 KB |
Output is correct |
48 |
Correct |
189 ms |
65016 KB |
Output is correct |
49 |
Correct |
184 ms |
63644 KB |
Output is correct |
50 |
Correct |
164 ms |
38400 KB |
Output is correct |
51 |
Correct |
173 ms |
38408 KB |
Output is correct |
52 |
Correct |
204 ms |
38548 KB |
Output is correct |
53 |
Correct |
177 ms |
37092 KB |
Output is correct |
54 |
Correct |
272 ms |
62068 KB |
Output is correct |
55 |
Correct |
19 ms |
18236 KB |
Output is correct |
56 |
Correct |
13 ms |
17192 KB |
Output is correct |
57 |
Correct |
61 ms |
29148 KB |
Output is correct |
58 |
Correct |
48 ms |
26788 KB |
Output is correct |
59 |
Correct |
67 ms |
40388 KB |
Output is correct |
60 |
Correct |
178 ms |
63952 KB |
Output is correct |
61 |
Correct |
203 ms |
41088 KB |
Output is correct |
62 |
Correct |
160 ms |
38492 KB |
Output is correct |
63 |
Correct |
200 ms |
38452 KB |
Output is correct |
64 |
Correct |
396 ms |
78268 KB |
Output is correct |
65 |
Correct |
371 ms |
78020 KB |
Output is correct |
66 |
Correct |
205 ms |
60776 KB |
Output is correct |
67 |
Correct |
160 ms |
38888 KB |
Output is correct |
68 |
Correct |
305 ms |
52956 KB |
Output is correct |
69 |
Correct |
324 ms |
56772 KB |
Output is correct |
70 |
Correct |
285 ms |
51520 KB |
Output is correct |