답안 #1098865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098865 2024-10-10T09:01:04 Z vjudge1 경주 (Race) (IOI11_race) C++17
100 / 100
380 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 6 ms 14428 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 14528 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14584 KB Output is correct
13 Correct 6 ms 14340 KB Output is correct
14 Correct 6 ms 14428 KB Output is correct
15 Correct 6 ms 14536 KB Output is correct
16 Correct 5 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 6 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 6 ms 14428 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 14528 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14584 KB Output is correct
13 Correct 6 ms 14340 KB Output is correct
14 Correct 6 ms 14428 KB Output is correct
15 Correct 6 ms 14536 KB Output is correct
16 Correct 5 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 14536 KB Output is correct
20 Correct 6 ms 14428 KB Output is correct
21 Correct 6 ms 14684 KB Output is correct
22 Correct 7 ms 14684 KB Output is correct
23 Correct 7 ms 14684 KB Output is correct
24 Correct 6 ms 14844 KB Output is correct
25 Correct 6 ms 14752 KB Output is correct
26 Correct 6 ms 14684 KB Output is correct
27 Correct 6 ms 14684 KB Output is correct
28 Correct 6 ms 14708 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 14680 KB Output is correct
34 Correct 7 ms 14684 KB Output is correct
35 Correct 8 ms 14684 KB Output is correct
36 Correct 6 ms 14684 KB Output is correct
37 Correct 7 ms 14684 KB Output is correct
38 Correct 7 ms 14728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 6 ms 14428 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 14528 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14584 KB Output is correct
13 Correct 6 ms 14340 KB Output is correct
14 Correct 6 ms 14428 KB Output is correct
15 Correct 6 ms 14536 KB Output is correct
16 Correct 5 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 96 ms 37296 KB Output is correct
20 Correct 91 ms 37460 KB Output is correct
21 Correct 95 ms 37200 KB Output is correct
22 Correct 95 ms 36760 KB Output is correct
23 Correct 129 ms 49600 KB Output is correct
24 Correct 103 ms 40276 KB Output is correct
25 Correct 86 ms 37968 KB Output is correct
26 Correct 52 ms 46420 KB Output is correct
27 Correct 141 ms 48724 KB Output is correct
28 Correct 243 ms 90912 KB Output is correct
29 Correct 253 ms 89172 KB Output is correct
30 Correct 144 ms 48636 KB Output is correct
31 Correct 131 ms 48572 KB Output is correct
32 Correct 183 ms 48724 KB Output is correct
33 Correct 205 ms 53636 KB Output is correct
34 Correct 295 ms 86588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 6 ms 14428 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 14528 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14584 KB Output is correct
13 Correct 6 ms 14340 KB Output is correct
14 Correct 6 ms 14428 KB Output is correct
15 Correct 6 ms 14536 KB Output is correct
16 Correct 5 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 14536 KB Output is correct
20 Correct 6 ms 14428 KB Output is correct
21 Correct 6 ms 14684 KB Output is correct
22 Correct 7 ms 14684 KB Output is correct
23 Correct 7 ms 14684 KB Output is correct
24 Correct 6 ms 14844 KB Output is correct
25 Correct 6 ms 14752 KB Output is correct
26 Correct 6 ms 14684 KB Output is correct
27 Correct 6 ms 14684 KB Output is correct
28 Correct 6 ms 14708 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 14680 KB Output is correct
34 Correct 7 ms 14684 KB Output is correct
35 Correct 8 ms 14684 KB Output is correct
36 Correct 6 ms 14684 KB Output is correct
37 Correct 7 ms 14684 KB Output is correct
38 Correct 7 ms 14728 KB Output is correct
39 Correct 96 ms 37296 KB Output is correct
40 Correct 91 ms 37460 KB Output is correct
41 Correct 95 ms 37200 KB Output is correct
42 Correct 95 ms 36760 KB Output is correct
43 Correct 129 ms 49600 KB Output is correct
44 Correct 103 ms 40276 KB Output is correct
45 Correct 86 ms 37968 KB Output is correct
46 Correct 52 ms 46420 KB Output is correct
47 Correct 141 ms 48724 KB Output is correct
48 Correct 243 ms 90912 KB Output is correct
49 Correct 253 ms 89172 KB Output is correct
50 Correct 144 ms 48636 KB Output is correct
51 Correct 131 ms 48572 KB Output is correct
52 Correct 183 ms 48724 KB Output is correct
53 Correct 205 ms 53636 KB Output is correct
54 Correct 295 ms 86588 KB Output is correct
55 Correct 18 ms 17752 KB Output is correct
56 Correct 12 ms 16476 KB Output is correct
57 Correct 59 ms 34652 KB Output is correct
58 Correct 46 ms 28136 KB Output is correct
59 Correct 78 ms 52560 KB Output is correct
60 Correct 249 ms 89428 KB Output is correct
61 Correct 175 ms 52108 KB Output is correct
62 Correct 147 ms 48724 KB Output is correct
63 Correct 180 ms 48800 KB Output is correct
64 Correct 380 ms 104016 KB Output is correct
65 Correct 356 ms 101968 KB Output is correct
66 Correct 226 ms 85136 KB Output is correct
67 Correct 120 ms 43052 KB Output is correct
68 Correct 248 ms 65672 KB Output is correct
69 Correct 278 ms 70780 KB Output is correct
70 Correct 234 ms 63568 KB Output is correct