# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
552880 |
2022-04-24T09:05:00 Z |
DrearyJoke |
Race (IOI11_race) |
C++17 |
|
501 ms |
79092 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define END "\n"
#define rall(v) (v).rbegin(), (v).rend()
#define all(v) (v).begin(), (v).end()
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int best_path(int n, int k, int H[][2], int L[]) {
vector<vector<pii>> adj(n);
for (int i = 0; i < n - 1; ++i) {
adj[H[i][0]].push_back({H[i][1], L[i]});
adj[H[i][1]].push_back({H[i][0], L[i]});
}
int ans = INT_MAX;
function<map<ll, int>(int, int, int, ll)> dfs = [&](int v, int p, int d, ll l) -> map<ll, int> {
map<ll, int> mp;
mp[l] = d;
for (auto u : adj[v]) {
if (u.ff != p) {
auto ret = dfs(u.ff, v, d + 1, l + u.ss);
if (mp.size() < ret.size()) swap(mp, ret);
for (auto x : ret) {
if (mp.find(k - x.ff + l * 2) != mp.end()) {
int pp = mp[k - x.ff + l * 2];
ans = min(ans, pp + x.ss - 2 * d);
}
}
for (auto x : ret) {
if (mp.find(x.ff) == mp.end()) mp[x.ff] = x.ss;
else mp[x.ff] = min(mp[x.ff], x.ss);
}
}
}
return mp;
};
dfs(0, -1, 0, 0);
return ans == INT_MAX ? -1 : ans;
// return n;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
84 ms |
7584 KB |
Output is correct |
20 |
Correct |
83 ms |
7480 KB |
Output is correct |
21 |
Correct |
78 ms |
7572 KB |
Output is correct |
22 |
Correct |
92 ms |
7608 KB |
Output is correct |
23 |
Correct |
111 ms |
7920 KB |
Output is correct |
24 |
Correct |
87 ms |
7608 KB |
Output is correct |
25 |
Correct |
73 ms |
24552 KB |
Output is correct |
26 |
Correct |
59 ms |
39804 KB |
Output is correct |
27 |
Correct |
173 ms |
15244 KB |
Output is correct |
28 |
Correct |
258 ms |
79092 KB |
Output is correct |
29 |
Correct |
247 ms |
76172 KB |
Output is correct |
30 |
Correct |
180 ms |
15320 KB |
Output is correct |
31 |
Correct |
185 ms |
15248 KB |
Output is correct |
32 |
Correct |
199 ms |
15332 KB |
Output is correct |
33 |
Correct |
189 ms |
14928 KB |
Output is correct |
34 |
Correct |
330 ms |
27468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
476 KB |
Output is correct |
39 |
Correct |
84 ms |
7584 KB |
Output is correct |
40 |
Correct |
83 ms |
7480 KB |
Output is correct |
41 |
Correct |
78 ms |
7572 KB |
Output is correct |
42 |
Correct |
92 ms |
7608 KB |
Output is correct |
43 |
Correct |
111 ms |
7920 KB |
Output is correct |
44 |
Correct |
87 ms |
7608 KB |
Output is correct |
45 |
Correct |
73 ms |
24552 KB |
Output is correct |
46 |
Correct |
59 ms |
39804 KB |
Output is correct |
47 |
Correct |
173 ms |
15244 KB |
Output is correct |
48 |
Correct |
258 ms |
79092 KB |
Output is correct |
49 |
Correct |
247 ms |
76172 KB |
Output is correct |
50 |
Correct |
180 ms |
15320 KB |
Output is correct |
51 |
Correct |
185 ms |
15248 KB |
Output is correct |
52 |
Correct |
199 ms |
15332 KB |
Output is correct |
53 |
Correct |
189 ms |
14928 KB |
Output is correct |
54 |
Correct |
330 ms |
27468 KB |
Output is correct |
55 |
Correct |
13 ms |
1492 KB |
Output is correct |
56 |
Correct |
6 ms |
980 KB |
Output is correct |
57 |
Correct |
54 ms |
7648 KB |
Output is correct |
58 |
Correct |
44 ms |
7776 KB |
Output is correct |
59 |
Correct |
103 ms |
39752 KB |
Output is correct |
60 |
Correct |
250 ms |
77160 KB |
Output is correct |
61 |
Correct |
225 ms |
16972 KB |
Output is correct |
62 |
Correct |
161 ms |
15152 KB |
Output is correct |
63 |
Correct |
223 ms |
15296 KB |
Output is correct |
64 |
Correct |
472 ms |
23320 KB |
Output is correct |
65 |
Correct |
501 ms |
27472 KB |
Output is correct |
66 |
Correct |
301 ms |
69280 KB |
Output is correct |
67 |
Correct |
163 ms |
15288 KB |
Output is correct |
68 |
Correct |
347 ms |
25712 KB |
Output is correct |
69 |
Correct |
325 ms |
30216 KB |
Output is correct |
70 |
Correct |
300 ms |
24724 KB |
Output is correct |