# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1100485 |
2024-10-14T04:59:42 Z |
sssamui |
Race (IOI11_race) |
C++17 |
|
393 ms |
108668 KB |
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
using ll = long long;
const int MXN = 2e5;
vector<vector<pair<int, ll>>> adj(MXN, vector<pair<int, ll>>(0));
vector<int> dep(MXN, 0);
vector<ll> dtr(MXN, 0);
vector<map<ll, int>> tmerg(MXN);
int ans = MXN;
int k;
void dfs(int node = 0, int p = -1)
{
tmerg[node][dtr[node]] = dep[node];
for (pair<int, ll> nxt : adj[node]) if (nxt.first != p)
{
dep[nxt.first] = dep[node] + 1, dtr[nxt.first] = dtr[node] + nxt.second;
dfs(nxt.first, node);
if (tmerg[node].size() < tmerg[nxt.first].size()) swap(tmerg[node], tmerg[nxt.first]);
for (pair<ll, int> tins : tmerg[nxt.first]) if (tmerg[node].count(k - tins.first + 2 * dtr[node]) == 1) ans = fmin(ans, tins.second - 2 *
dep[node] + tmerg[node][k - tins.first + 2 * dtr[node]]);
for (pair<ll, int> tins : tmerg[nxt.first]) if ((tmerg[node].count(tins.first) == 0) || (tmerg[node][tins.first] > tins.second))
tmerg[node][tins.first] = tins.second;
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
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] });
dfs();
if (ans == MXN) return -1;
else return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18768 KB |
Output is correct |
2 |
Correct |
6 ms |
18768 KB |
Output is correct |
3 |
Correct |
6 ms |
18768 KB |
Output is correct |
4 |
Correct |
6 ms |
18792 KB |
Output is correct |
5 |
Correct |
5 ms |
18768 KB |
Output is correct |
6 |
Correct |
6 ms |
18972 KB |
Output is correct |
7 |
Correct |
6 ms |
18768 KB |
Output is correct |
8 |
Correct |
6 ms |
18952 KB |
Output is correct |
9 |
Correct |
6 ms |
18780 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18816 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
6 ms |
18784 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18780 KB |
Output is correct |
17 |
Correct |
5 ms |
18768 KB |
Output is correct |
18 |
Correct |
6 ms |
18768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18768 KB |
Output is correct |
2 |
Correct |
6 ms |
18768 KB |
Output is correct |
3 |
Correct |
6 ms |
18768 KB |
Output is correct |
4 |
Correct |
6 ms |
18792 KB |
Output is correct |
5 |
Correct |
5 ms |
18768 KB |
Output is correct |
6 |
Correct |
6 ms |
18972 KB |
Output is correct |
7 |
Correct |
6 ms |
18768 KB |
Output is correct |
8 |
Correct |
6 ms |
18952 KB |
Output is correct |
9 |
Correct |
6 ms |
18780 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18816 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
6 ms |
18784 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18780 KB |
Output is correct |
17 |
Correct |
5 ms |
18768 KB |
Output is correct |
18 |
Correct |
6 ms |
18768 KB |
Output is correct |
19 |
Correct |
5 ms |
18768 KB |
Output is correct |
20 |
Correct |
5 ms |
18768 KB |
Output is correct |
21 |
Correct |
7 ms |
19024 KB |
Output is correct |
22 |
Correct |
6 ms |
19180 KB |
Output is correct |
23 |
Correct |
7 ms |
19024 KB |
Output is correct |
24 |
Correct |
7 ms |
19192 KB |
Output is correct |
25 |
Correct |
7 ms |
19024 KB |
Output is correct |
26 |
Correct |
9 ms |
19024 KB |
Output is correct |
27 |
Correct |
6 ms |
19024 KB |
Output is correct |
28 |
Correct |
6 ms |
19024 KB |
Output is correct |
29 |
Correct |
6 ms |
19192 KB |
Output is correct |
30 |
Correct |
6 ms |
19024 KB |
Output is correct |
31 |
Correct |
6 ms |
19024 KB |
Output is correct |
32 |
Correct |
6 ms |
19024 KB |
Output is correct |
33 |
Correct |
6 ms |
19192 KB |
Output is correct |
34 |
Correct |
7 ms |
19036 KB |
Output is correct |
35 |
Correct |
6 ms |
19292 KB |
Output is correct |
36 |
Correct |
6 ms |
19036 KB |
Output is correct |
37 |
Correct |
6 ms |
19024 KB |
Output is correct |
38 |
Correct |
7 ms |
19024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18768 KB |
Output is correct |
2 |
Correct |
6 ms |
18768 KB |
Output is correct |
3 |
Correct |
6 ms |
18768 KB |
Output is correct |
4 |
Correct |
6 ms |
18792 KB |
Output is correct |
5 |
Correct |
5 ms |
18768 KB |
Output is correct |
6 |
Correct |
6 ms |
18972 KB |
Output is correct |
7 |
Correct |
6 ms |
18768 KB |
Output is correct |
8 |
Correct |
6 ms |
18952 KB |
Output is correct |
9 |
Correct |
6 ms |
18780 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18816 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
6 ms |
18784 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18780 KB |
Output is correct |
17 |
Correct |
5 ms |
18768 KB |
Output is correct |
18 |
Correct |
6 ms |
18768 KB |
Output is correct |
19 |
Correct |
92 ms |
41800 KB |
Output is correct |
20 |
Correct |
81 ms |
42980 KB |
Output is correct |
21 |
Correct |
93 ms |
42836 KB |
Output is correct |
22 |
Correct |
88 ms |
42324 KB |
Output is correct |
23 |
Correct |
129 ms |
55396 KB |
Output is correct |
24 |
Correct |
91 ms |
45396 KB |
Output is correct |
25 |
Correct |
94 ms |
44760 KB |
Output is correct |
26 |
Correct |
61 ms |
53576 KB |
Output is correct |
27 |
Correct |
140 ms |
53808 KB |
Output is correct |
28 |
Correct |
237 ms |
99224 KB |
Output is correct |
29 |
Correct |
249 ms |
97052 KB |
Output is correct |
30 |
Correct |
147 ms |
53844 KB |
Output is correct |
31 |
Correct |
133 ms |
53840 KB |
Output is correct |
32 |
Correct |
169 ms |
54096 KB |
Output is correct |
33 |
Correct |
150 ms |
58768 KB |
Output is correct |
34 |
Correct |
256 ms |
91548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18768 KB |
Output is correct |
2 |
Correct |
6 ms |
18768 KB |
Output is correct |
3 |
Correct |
6 ms |
18768 KB |
Output is correct |
4 |
Correct |
6 ms |
18792 KB |
Output is correct |
5 |
Correct |
5 ms |
18768 KB |
Output is correct |
6 |
Correct |
6 ms |
18972 KB |
Output is correct |
7 |
Correct |
6 ms |
18768 KB |
Output is correct |
8 |
Correct |
6 ms |
18952 KB |
Output is correct |
9 |
Correct |
6 ms |
18780 KB |
Output is correct |
10 |
Correct |
5 ms |
18780 KB |
Output is correct |
11 |
Correct |
6 ms |
18816 KB |
Output is correct |
12 |
Correct |
5 ms |
18780 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
6 ms |
18784 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18780 KB |
Output is correct |
17 |
Correct |
5 ms |
18768 KB |
Output is correct |
18 |
Correct |
6 ms |
18768 KB |
Output is correct |
19 |
Correct |
5 ms |
18768 KB |
Output is correct |
20 |
Correct |
5 ms |
18768 KB |
Output is correct |
21 |
Correct |
7 ms |
19024 KB |
Output is correct |
22 |
Correct |
6 ms |
19180 KB |
Output is correct |
23 |
Correct |
7 ms |
19024 KB |
Output is correct |
24 |
Correct |
7 ms |
19192 KB |
Output is correct |
25 |
Correct |
7 ms |
19024 KB |
Output is correct |
26 |
Correct |
9 ms |
19024 KB |
Output is correct |
27 |
Correct |
6 ms |
19024 KB |
Output is correct |
28 |
Correct |
6 ms |
19024 KB |
Output is correct |
29 |
Correct |
6 ms |
19192 KB |
Output is correct |
30 |
Correct |
6 ms |
19024 KB |
Output is correct |
31 |
Correct |
6 ms |
19024 KB |
Output is correct |
32 |
Correct |
6 ms |
19024 KB |
Output is correct |
33 |
Correct |
6 ms |
19192 KB |
Output is correct |
34 |
Correct |
7 ms |
19036 KB |
Output is correct |
35 |
Correct |
6 ms |
19292 KB |
Output is correct |
36 |
Correct |
6 ms |
19036 KB |
Output is correct |
37 |
Correct |
6 ms |
19024 KB |
Output is correct |
38 |
Correct |
7 ms |
19024 KB |
Output is correct |
39 |
Correct |
92 ms |
41800 KB |
Output is correct |
40 |
Correct |
81 ms |
42980 KB |
Output is correct |
41 |
Correct |
93 ms |
42836 KB |
Output is correct |
42 |
Correct |
88 ms |
42324 KB |
Output is correct |
43 |
Correct |
129 ms |
55396 KB |
Output is correct |
44 |
Correct |
91 ms |
45396 KB |
Output is correct |
45 |
Correct |
94 ms |
44760 KB |
Output is correct |
46 |
Correct |
61 ms |
53576 KB |
Output is correct |
47 |
Correct |
140 ms |
53808 KB |
Output is correct |
48 |
Correct |
237 ms |
99224 KB |
Output is correct |
49 |
Correct |
249 ms |
97052 KB |
Output is correct |
50 |
Correct |
147 ms |
53844 KB |
Output is correct |
51 |
Correct |
133 ms |
53840 KB |
Output is correct |
52 |
Correct |
169 ms |
54096 KB |
Output is correct |
53 |
Correct |
150 ms |
58768 KB |
Output is correct |
54 |
Correct |
256 ms |
91548 KB |
Output is correct |
55 |
Correct |
15 ms |
22096 KB |
Output is correct |
56 |
Correct |
11 ms |
20816 KB |
Output is correct |
57 |
Correct |
61 ms |
40668 KB |
Output is correct |
58 |
Correct |
40 ms |
33464 KB |
Output is correct |
59 |
Correct |
92 ms |
59956 KB |
Output is correct |
60 |
Correct |
239 ms |
97608 KB |
Output is correct |
61 |
Correct |
179 ms |
57424 KB |
Output is correct |
62 |
Correct |
140 ms |
53832 KB |
Output is correct |
63 |
Correct |
187 ms |
53832 KB |
Output is correct |
64 |
Correct |
393 ms |
108668 KB |
Output is correct |
65 |
Correct |
368 ms |
106824 KB |
Output is correct |
66 |
Correct |
314 ms |
92600 KB |
Output is correct |
67 |
Correct |
132 ms |
47608 KB |
Output is correct |
68 |
Correct |
277 ms |
70212 KB |
Output is correct |
69 |
Correct |
305 ms |
75108 KB |
Output is correct |
70 |
Correct |
279 ms |
68092 KB |
Output is correct |