# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484193 |
2021-11-02T10:57:44 Z |
FEDIKUS |
Race (IOI11_race) |
C++17 |
|
382 ms |
74980 KB |
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#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 |
15948 KB |
Output is correct |
2 |
Correct |
7 ms |
15948 KB |
Output is correct |
3 |
Correct |
9 ms |
15948 KB |
Output is correct |
4 |
Correct |
8 ms |
15980 KB |
Output is correct |
5 |
Correct |
7 ms |
15948 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15900 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
8 ms |
15892 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
8 ms |
15948 KB |
Output is correct |
14 |
Correct |
8 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15936 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
7 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
7 ms |
15948 KB |
Output is correct |
3 |
Correct |
9 ms |
15948 KB |
Output is correct |
4 |
Correct |
8 ms |
15980 KB |
Output is correct |
5 |
Correct |
7 ms |
15948 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15900 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
8 ms |
15892 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
8 ms |
15948 KB |
Output is correct |
14 |
Correct |
8 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15936 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
7 ms |
15948 KB |
Output is correct |
19 |
Correct |
8 ms |
15948 KB |
Output is correct |
20 |
Correct |
7 ms |
15948 KB |
Output is correct |
21 |
Correct |
9 ms |
16204 KB |
Output is correct |
22 |
Correct |
9 ms |
16076 KB |
Output is correct |
23 |
Correct |
9 ms |
16076 KB |
Output is correct |
24 |
Correct |
10 ms |
16120 KB |
Output is correct |
25 |
Correct |
9 ms |
16108 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
8 ms |
15948 KB |
Output is correct |
28 |
Correct |
9 ms |
16048 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 |
16168 KB |
Output is correct |
32 |
Correct |
9 ms |
16076 KB |
Output is correct |
33 |
Correct |
9 ms |
16076 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 |
16084 KB |
Output is correct |
37 |
Correct |
8 ms |
16076 KB |
Output is correct |
38 |
Correct |
8 ms |
16068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
7 ms |
15948 KB |
Output is correct |
3 |
Correct |
9 ms |
15948 KB |
Output is correct |
4 |
Correct |
8 ms |
15980 KB |
Output is correct |
5 |
Correct |
7 ms |
15948 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15900 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
8 ms |
15892 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
8 ms |
15948 KB |
Output is correct |
14 |
Correct |
8 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15936 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
7 ms |
15948 KB |
Output is correct |
19 |
Correct |
107 ms |
29336 KB |
Output is correct |
20 |
Correct |
100 ms |
29192 KB |
Output is correct |
21 |
Correct |
97 ms |
29196 KB |
Output is correct |
22 |
Correct |
100 ms |
29252 KB |
Output is correct |
23 |
Correct |
134 ms |
38984 KB |
Output is correct |
24 |
Correct |
118 ms |
34048 KB |
Output is correct |
25 |
Correct |
66 ms |
28952 KB |
Output is correct |
26 |
Correct |
48 ms |
35844 KB |
Output is correct |
27 |
Correct |
166 ms |
35396 KB |
Output is correct |
28 |
Correct |
183 ms |
65136 KB |
Output is correct |
29 |
Correct |
194 ms |
63444 KB |
Output is correct |
30 |
Correct |
162 ms |
35396 KB |
Output is correct |
31 |
Correct |
159 ms |
35396 KB |
Output is correct |
32 |
Correct |
209 ms |
35636 KB |
Output is correct |
33 |
Correct |
189 ms |
34208 KB |
Output is correct |
34 |
Correct |
272 ms |
58280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
2 |
Correct |
7 ms |
15948 KB |
Output is correct |
3 |
Correct |
9 ms |
15948 KB |
Output is correct |
4 |
Correct |
8 ms |
15980 KB |
Output is correct |
5 |
Correct |
7 ms |
15948 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15900 KB |
Output is correct |
8 |
Correct |
8 ms |
15948 KB |
Output is correct |
9 |
Correct |
8 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15948 KB |
Output is correct |
11 |
Correct |
8 ms |
15892 KB |
Output is correct |
12 |
Correct |
8 ms |
15948 KB |
Output is correct |
13 |
Correct |
8 ms |
15948 KB |
Output is correct |
14 |
Correct |
8 ms |
15948 KB |
Output is correct |
15 |
Correct |
7 ms |
15936 KB |
Output is correct |
16 |
Correct |
8 ms |
15948 KB |
Output is correct |
17 |
Correct |
8 ms |
15948 KB |
Output is correct |
18 |
Correct |
7 ms |
15948 KB |
Output is correct |
19 |
Correct |
8 ms |
15948 KB |
Output is correct |
20 |
Correct |
7 ms |
15948 KB |
Output is correct |
21 |
Correct |
9 ms |
16204 KB |
Output is correct |
22 |
Correct |
9 ms |
16076 KB |
Output is correct |
23 |
Correct |
9 ms |
16076 KB |
Output is correct |
24 |
Correct |
10 ms |
16120 KB |
Output is correct |
25 |
Correct |
9 ms |
16108 KB |
Output is correct |
26 |
Correct |
9 ms |
16076 KB |
Output is correct |
27 |
Correct |
8 ms |
15948 KB |
Output is correct |
28 |
Correct |
9 ms |
16048 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 |
16168 KB |
Output is correct |
32 |
Correct |
9 ms |
16076 KB |
Output is correct |
33 |
Correct |
9 ms |
16076 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 |
16084 KB |
Output is correct |
37 |
Correct |
8 ms |
16076 KB |
Output is correct |
38 |
Correct |
8 ms |
16068 KB |
Output is correct |
39 |
Correct |
107 ms |
29336 KB |
Output is correct |
40 |
Correct |
100 ms |
29192 KB |
Output is correct |
41 |
Correct |
97 ms |
29196 KB |
Output is correct |
42 |
Correct |
100 ms |
29252 KB |
Output is correct |
43 |
Correct |
134 ms |
38984 KB |
Output is correct |
44 |
Correct |
118 ms |
34048 KB |
Output is correct |
45 |
Correct |
66 ms |
28952 KB |
Output is correct |
46 |
Correct |
48 ms |
35844 KB |
Output is correct |
47 |
Correct |
166 ms |
35396 KB |
Output is correct |
48 |
Correct |
183 ms |
65136 KB |
Output is correct |
49 |
Correct |
194 ms |
63444 KB |
Output is correct |
50 |
Correct |
162 ms |
35396 KB |
Output is correct |
51 |
Correct |
159 ms |
35396 KB |
Output is correct |
52 |
Correct |
209 ms |
35636 KB |
Output is correct |
53 |
Correct |
189 ms |
34208 KB |
Output is correct |
54 |
Correct |
272 ms |
58280 KB |
Output is correct |
55 |
Correct |
21 ms |
18080 KB |
Output is correct |
56 |
Correct |
13 ms |
16972 KB |
Output is correct |
57 |
Correct |
69 ms |
28164 KB |
Output is correct |
58 |
Correct |
48 ms |
25656 KB |
Output is correct |
59 |
Correct |
69 ms |
40516 KB |
Output is correct |
60 |
Correct |
181 ms |
64176 KB |
Output is correct |
61 |
Correct |
204 ms |
38212 KB |
Output is correct |
62 |
Correct |
159 ms |
35556 KB |
Output is correct |
63 |
Correct |
202 ms |
35604 KB |
Output is correct |
64 |
Correct |
382 ms |
74980 KB |
Output is correct |
65 |
Correct |
372 ms |
74304 KB |
Output is correct |
66 |
Correct |
195 ms |
59956 KB |
Output is correct |
67 |
Correct |
152 ms |
35696 KB |
Output is correct |
68 |
Correct |
288 ms |
49476 KB |
Output is correct |
69 |
Correct |
317 ms |
53368 KB |
Output is correct |
70 |
Correct |
289 ms |
48192 KB |
Output is correct |