Submission #848322

# Submission time Handle Problem Language Result Execution time Memory
848322 2023-09-12T06:17:59 Z victor_gao Race (IOI11_race) C++17
100 / 100
324 ms 66136 KB
#include "race.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
#define MAXN 200015
#define MAXC 1000005
using namespace std;
int sz[MAXN], dep[MAXN], mx[MAXN], use[MAXN];
int ans = 2e9, t = 0, k, in[MAXN], out[MAXN], tag = 0;
vector<pii> g[MAXN];
vector<int> path;
multiset<pii> st;
void dfs(int p, int lp) {
    sz[p] = 1;
    mx[p] = -1;
    path.push_back(p);
    in[p] = t++;
    for (auto [i, c] : g[p]) {
        if (i != lp) {
            dep[i] = dep[p] + c;
            use[i] = use[p] + 1;
            dfs(i, p);
            sz[p] += sz[i];
            mx[p] = (mx[p] == -1 || sz[mx[p]] < sz[i]) ? i : mx[p];
        }
    }
    out[p] = t;
}
int query(int p, int i) {
    if (st.empty())
        return 2e9;
    int need = k + 2 * dep[p] - dep[i];
    auto it = st.lower_bound(pii(need, -1));
    if (it != st.end() && (it->x) == need)
        return it->y;
    return 2e9;
}
void dfs1(int p, int lp, bool flag) {
    for (auto [i, c] : g[p]) {
        if (i != lp && i != mx[p])
            dfs1(i, p, 0);
    }
    if (mx[p] >= 0)
        dfs1(mx[p], p, 1);
    for (auto [i, c] : g[p]) {
        if (i != lp && i != mx[p]) {
            for (int j = in[i]; j < out[i]; j++) {
                int a = path[j];
                ans = min(ans, use[a] + query(p, a) - 2 * use[p]);
            }
            for (int j = in[i]; j < out[i]; j++) {
                int a = path[j];
                st.insert(pii(dep[a], use[a]));
            }
        }
    }
    ans = min(ans, use[p] + query(p, p) - 2 * use[p]);
    st.insert(pii(dep[p], use[p]));
    if (!flag) {
        for (int i = in[p]; i < out[p]; i++) {
            int a = path[i];
            st.erase(st.find(pii(dep[a], use[a])));
        }
    }
}
int best_path(int N, int K, int H[][2], int L[]) {
    k = K;
    for (int i = 0; i < N - 1; i++) {
        g[H[i][0]].push_back({H[i][1], L[i]});
        g[H[i][1]].push_back({H[i][0], L[i]});
    }
    dfs(0, 0);
    dfs1(0, 0, 1);
    return ans > N ? -1 : ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12748 KB Output is correct
8 Correct 3 ms 12744 KB Output is correct
9 Correct 2 ms 12744 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12748 KB Output is correct
8 Correct 3 ms 12744 KB Output is correct
9 Correct 2 ms 12744 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 3 ms 12756 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 3 ms 12636 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 3 ms 12636 KB Output is correct
27 Correct 3 ms 12756 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 3 ms 12636 KB Output is correct
30 Correct 3 ms 12736 KB Output is correct
31 Correct 3 ms 12636 KB Output is correct
32 Correct 3 ms 12636 KB Output is correct
33 Correct 3 ms 12636 KB Output is correct
34 Correct 2 ms 12888 KB Output is correct
35 Correct 2 ms 12892 KB Output is correct
36 Correct 2 ms 12892 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12748 KB Output is correct
8 Correct 3 ms 12744 KB Output is correct
9 Correct 2 ms 12744 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 179 ms 25356 KB Output is correct
20 Correct 152 ms 25356 KB Output is correct
21 Correct 164 ms 25292 KB Output is correct
22 Correct 156 ms 25460 KB Output is correct
23 Correct 196 ms 25520 KB Output is correct
24 Correct 133 ms 25516 KB Output is correct
25 Correct 76 ms 33116 KB Output is correct
26 Correct 59 ms 40404 KB Output is correct
27 Correct 153 ms 36304 KB Output is correct
28 Correct 158 ms 66136 KB Output is correct
29 Correct 161 ms 63944 KB Output is correct
30 Correct 156 ms 36296 KB Output is correct
31 Correct 161 ms 36268 KB Output is correct
32 Correct 235 ms 36428 KB Output is correct
33 Correct 199 ms 35348 KB Output is correct
34 Correct 213 ms 36036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12748 KB Output is correct
8 Correct 3 ms 12744 KB Output is correct
9 Correct 2 ms 12744 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 3 ms 12756 KB Output is correct
22 Correct 3 ms 12636 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 3 ms 12636 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 3 ms 12636 KB Output is correct
27 Correct 3 ms 12756 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 3 ms 12636 KB Output is correct
30 Correct 3 ms 12736 KB Output is correct
31 Correct 3 ms 12636 KB Output is correct
32 Correct 3 ms 12636 KB Output is correct
33 Correct 3 ms 12636 KB Output is correct
34 Correct 2 ms 12888 KB Output is correct
35 Correct 2 ms 12892 KB Output is correct
36 Correct 2 ms 12892 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
39 Correct 179 ms 25356 KB Output is correct
40 Correct 152 ms 25356 KB Output is correct
41 Correct 164 ms 25292 KB Output is correct
42 Correct 156 ms 25460 KB Output is correct
43 Correct 196 ms 25520 KB Output is correct
44 Correct 133 ms 25516 KB Output is correct
45 Correct 76 ms 33116 KB Output is correct
46 Correct 59 ms 40404 KB Output is correct
47 Correct 153 ms 36304 KB Output is correct
48 Correct 158 ms 66136 KB Output is correct
49 Correct 161 ms 63944 KB Output is correct
50 Correct 156 ms 36296 KB Output is correct
51 Correct 161 ms 36268 KB Output is correct
52 Correct 235 ms 36428 KB Output is correct
53 Correct 199 ms 35348 KB Output is correct
54 Correct 213 ms 36036 KB Output is correct
55 Correct 11 ms 13656 KB Output is correct
56 Correct 12 ms 13660 KB Output is correct
57 Correct 165 ms 25432 KB Output is correct
58 Correct 77 ms 25176 KB Output is correct
59 Correct 60 ms 40520 KB Output is correct
60 Correct 149 ms 64708 KB Output is correct
61 Correct 165 ms 36308 KB Output is correct
62 Correct 151 ms 36364 KB Output is correct
63 Correct 179 ms 36300 KB Output is correct
64 Correct 324 ms 36612 KB Output is correct
65 Correct 296 ms 37320 KB Output is correct
66 Correct 166 ms 59044 KB Output is correct
67 Correct 146 ms 36936 KB Output is correct
68 Correct 202 ms 37056 KB Output is correct
69 Correct 225 ms 37272 KB Output is correct
70 Correct 182 ms 35988 KB Output is correct