# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
395992 |
2021-04-29T10:14:09 Z |
Jarif_Rahman |
Race (IOI11_race) |
C++17 |
|
494 ms |
76116 KB |
#include "race.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e18;
ll k;
vector<set<pair<ll, int>>> s;
vector<vector<pair<int, ll>>> v;
ll ans = 1e18;
void dfs(int nd, int ss, ll dis, int depth){
for(auto [x, w]: v[nd]) if(x != ss) dfs(x, nd, dis+w, depth+1);
int mx = -1, in = -1;
for(auto [x, w]: v[nd]) if(x != ss){
if((int)s[x].size() > mx){
mx = s[x].size();
in = x;
}
}
if(in != -1) swap(s[nd], s[in]);
auto it = s[nd].lower_bound(make_pair(k+dis, 0));
if(it != s[nd].end() && it->f == k+dis) ans = min(ans, (ll)it->sc - depth);
for(auto [x, w]: v[nd]) if(x != ss){
for(auto [d, dpt]: s[x]){
dpt-=depth;
d-=dis;
ll dd = k-d;
if(dd == 0){
ans = min(ans, (ll)dpt);
}
else{
auto it = s[nd].lower_bound(make_pair(dd+dis, 0));
if(it != s[nd].end() && it->f == dd+dis){
ans = min(ans, dpt+(ll)(it->sc)-depth);
}
}
}
for(auto p: s[x]) s[nd].insert(p);
s[x].clear();
}
s[nd].insert({dis, depth});
}
int best_path(int n, int k, int edges[][2], int w[]){
::k = k;
v.resize(n);
s.resize(n);
for(int i = 0; i < n-1; i++){
v[edges[i][0]].pb({edges[i][1], w[i]});
v[edges[i][1]].pb({edges[i][0], w[i]});
}
dfs(0, -1, 0LL, 0);
if(ans == inf) ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
444 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
496 KB |
Output is correct |
31 |
Correct |
2 ms |
464 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
2 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
440 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
130 ms |
15504 KB |
Output is correct |
20 |
Correct |
132 ms |
15580 KB |
Output is correct |
21 |
Correct |
119 ms |
15368 KB |
Output is correct |
22 |
Correct |
130 ms |
15420 KB |
Output is correct |
23 |
Correct |
149 ms |
16076 KB |
Output is correct |
24 |
Correct |
113 ms |
15044 KB |
Output is correct |
25 |
Correct |
130 ms |
32812 KB |
Output is correct |
26 |
Correct |
89 ms |
38048 KB |
Output is correct |
27 |
Correct |
219 ms |
36768 KB |
Output is correct |
28 |
Correct |
262 ms |
76116 KB |
Output is correct |
29 |
Correct |
267 ms |
74436 KB |
Output is correct |
30 |
Correct |
219 ms |
36880 KB |
Output is correct |
31 |
Correct |
219 ms |
36824 KB |
Output is correct |
32 |
Correct |
257 ms |
36856 KB |
Output is correct |
33 |
Correct |
222 ms |
29896 KB |
Output is correct |
34 |
Correct |
342 ms |
43348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
444 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
496 KB |
Output is correct |
31 |
Correct |
2 ms |
464 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
2 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
440 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
464 KB |
Output is correct |
39 |
Correct |
130 ms |
15504 KB |
Output is correct |
40 |
Correct |
132 ms |
15580 KB |
Output is correct |
41 |
Correct |
119 ms |
15368 KB |
Output is correct |
42 |
Correct |
130 ms |
15420 KB |
Output is correct |
43 |
Correct |
149 ms |
16076 KB |
Output is correct |
44 |
Correct |
113 ms |
15044 KB |
Output is correct |
45 |
Correct |
130 ms |
32812 KB |
Output is correct |
46 |
Correct |
89 ms |
38048 KB |
Output is correct |
47 |
Correct |
219 ms |
36768 KB |
Output is correct |
48 |
Correct |
262 ms |
76116 KB |
Output is correct |
49 |
Correct |
267 ms |
74436 KB |
Output is correct |
50 |
Correct |
219 ms |
36880 KB |
Output is correct |
51 |
Correct |
219 ms |
36824 KB |
Output is correct |
52 |
Correct |
257 ms |
36856 KB |
Output is correct |
53 |
Correct |
222 ms |
29896 KB |
Output is correct |
54 |
Correct |
342 ms |
43348 KB |
Output is correct |
55 |
Correct |
13 ms |
2380 KB |
Output is correct |
56 |
Correct |
9 ms |
1832 KB |
Output is correct |
57 |
Correct |
69 ms |
15300 KB |
Output is correct |
58 |
Correct |
61 ms |
20520 KB |
Output is correct |
59 |
Correct |
98 ms |
37960 KB |
Output is correct |
60 |
Correct |
291 ms |
74900 KB |
Output is correct |
61 |
Correct |
241 ms |
38696 KB |
Output is correct |
62 |
Correct |
210 ms |
36848 KB |
Output is correct |
63 |
Correct |
249 ms |
36868 KB |
Output is correct |
64 |
Correct |
419 ms |
42436 KB |
Output is correct |
65 |
Correct |
494 ms |
44212 KB |
Output is correct |
66 |
Correct |
281 ms |
71036 KB |
Output is correct |
67 |
Correct |
220 ms |
42052 KB |
Output is correct |
68 |
Correct |
330 ms |
42716 KB |
Output is correct |
69 |
Correct |
325 ms |
42948 KB |
Output is correct |
70 |
Correct |
306 ms |
40636 KB |
Output is correct |