Submission #1098576

# Submission time Handle Problem Language Result Execution time Memory
1098576 2024-10-09T15:48:25 Z SulA Race (IOI11_race) C++17
100 / 100
348 ms 104016 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<long long,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;

map<long long, int> stl[200'000];
vector<pair<int,int>> adj[200'000];
int dep[200'000], ans = 1e9;
long long dist[200'000], k;

void init(int u = 0, int p = 0) {
    stl[u][dist[u]] = dep[u];
    for (auto [v, w] : adj[u]) if (v != p) {
            dep[v] = dep[u] + 1;
            dist[v] = dist[u] + w;
            init(v, u);
        }
}

void dfs(int u = 0, int p = 0) {
    long long target = k + 2*dist[u];
    for (auto [v, w] : adj[u]) if (v != p) {
            dfs(v, u);

            if (stl[v].size() > stl[u].size()) swap(stl[u], stl[v]);
            for (auto [len, edges] : stl[v]) {
                if (stl[u].count(target - len)) {;
                    ans = min(ans, stl[u][target - len] + edges - 2*dep[u]);
                }
            }
            for (auto [len, edges] : stl[v]) {
                if (stl[u].count(len)) {
                    stl[u][len] = min(stl[u][len], edges);
                } else {
                    stl[u][len] = edges;
                }
            }
        }
//    cout << u << ":\n";
//    for (auto [len, edges] : stl[u]) cout << len << " " << edges << "\n";
//    cout << '\n';
}

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]].emplace_back(h[i][1], l[i]);
        adj[h[i][1]].emplace_back(h[i][0], l[i]);
    }
    init();
    dfs();
    return ans == 1e9 ? -1 : ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 7 ms 14724 KB Output is correct
4 Correct 6 ms 14684 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14424 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 6 ms 14584 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 7 ms 14724 KB Output is correct
4 Correct 6 ms 14684 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14424 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 6 ms 14584 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14428 KB Output is correct
19 Correct 6 ms 14424 KB Output is correct
20 Correct 6 ms 14428 KB Output is correct
21 Correct 7 ms 14684 KB Output is correct
22 Correct 6 ms 14772 KB Output is correct
23 Correct 8 ms 14684 KB Output is correct
24 Correct 7 ms 14684 KB Output is correct
25 Correct 7 ms 14684 KB Output is correct
26 Correct 8 ms 14684 KB Output is correct
27 Correct 7 ms 14684 KB Output is correct
28 Correct 7 ms 14680 KB Output is correct
29 Correct 7 ms 14684 KB Output is correct
30 Correct 7 ms 14684 KB Output is correct
31 Correct 6 ms 14804 KB Output is correct
32 Correct 7 ms 14684 KB Output is correct
33 Correct 6 ms 14684 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 6 ms 14684 KB Output is correct
36 Correct 7 ms 14684 KB Output is correct
37 Correct 6 ms 14684 KB Output is correct
38 Correct 6 ms 14768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 7 ms 14724 KB Output is correct
4 Correct 6 ms 14684 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14424 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 6 ms 14584 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14428 KB Output is correct
19 Correct 85 ms 37352 KB Output is correct
20 Correct 85 ms 37340 KB Output is correct
21 Correct 85 ms 37200 KB Output is correct
22 Correct 86 ms 36692 KB Output is correct
23 Correct 142 ms 49488 KB Output is correct
24 Correct 91 ms 40056 KB Output is correct
25 Correct 75 ms 38192 KB Output is correct
26 Correct 47 ms 46164 KB Output is correct
27 Correct 142 ms 48720 KB Output is correct
28 Correct 222 ms 91028 KB Output is correct
29 Correct 225 ms 89168 KB Output is correct
30 Correct 137 ms 48724 KB Output is correct
31 Correct 174 ms 48648 KB Output is correct
32 Correct 162 ms 48940 KB Output is correct
33 Correct 183 ms 53592 KB Output is correct
34 Correct 268 ms 86468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 7 ms 14724 KB Output is correct
4 Correct 6 ms 14684 KB Output is correct
5 Correct 6 ms 14428 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 6 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14424 KB Output is correct
11 Correct 7 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 6 ms 14584 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 6 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14428 KB Output is correct
19 Correct 6 ms 14424 KB Output is correct
20 Correct 6 ms 14428 KB Output is correct
21 Correct 7 ms 14684 KB Output is correct
22 Correct 6 ms 14772 KB Output is correct
23 Correct 8 ms 14684 KB Output is correct
24 Correct 7 ms 14684 KB Output is correct
25 Correct 7 ms 14684 KB Output is correct
26 Correct 8 ms 14684 KB Output is correct
27 Correct 7 ms 14684 KB Output is correct
28 Correct 7 ms 14680 KB Output is correct
29 Correct 7 ms 14684 KB Output is correct
30 Correct 7 ms 14684 KB Output is correct
31 Correct 6 ms 14804 KB Output is correct
32 Correct 7 ms 14684 KB Output is correct
33 Correct 6 ms 14684 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 6 ms 14684 KB Output is correct
36 Correct 7 ms 14684 KB Output is correct
37 Correct 6 ms 14684 KB Output is correct
38 Correct 6 ms 14768 KB Output is correct
39 Correct 85 ms 37352 KB Output is correct
40 Correct 85 ms 37340 KB Output is correct
41 Correct 85 ms 37200 KB Output is correct
42 Correct 86 ms 36692 KB Output is correct
43 Correct 142 ms 49488 KB Output is correct
44 Correct 91 ms 40056 KB Output is correct
45 Correct 75 ms 38192 KB Output is correct
46 Correct 47 ms 46164 KB Output is correct
47 Correct 142 ms 48720 KB Output is correct
48 Correct 222 ms 91028 KB Output is correct
49 Correct 225 ms 89168 KB Output is correct
50 Correct 137 ms 48724 KB Output is correct
51 Correct 174 ms 48648 KB Output is correct
52 Correct 162 ms 48940 KB Output is correct
53 Correct 183 ms 53592 KB Output is correct
54 Correct 268 ms 86468 KB Output is correct
55 Correct 18 ms 17748 KB Output is correct
56 Correct 12 ms 16400 KB Output is correct
57 Correct 52 ms 34824 KB Output is correct
58 Correct 40 ms 28100 KB Output is correct
59 Correct 75 ms 52564 KB Output is correct
60 Correct 213 ms 89556 KB Output is correct
61 Correct 157 ms 52304 KB Output is correct
62 Correct 128 ms 48812 KB Output is correct
63 Correct 165 ms 48724 KB Output is correct
64 Correct 348 ms 104016 KB Output is correct
65 Correct 336 ms 101972 KB Output is correct
66 Correct 234 ms 85072 KB Output is correct
67 Correct 141 ms 43196 KB Output is correct
68 Correct 272 ms 65620 KB Output is correct
69 Correct 304 ms 70736 KB Output is correct
70 Correct 282 ms 63572 KB Output is correct