Submission #990370

# Submission time Handle Problem Language Result Execution time Memory
990370 2024-05-30T10:21:27 Z stdfloat Race (IOI11_race) C++17
100 / 100
735 ms 50260 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;

using ll = long long;

#define ff  first
#define ss  second
#define pii pair<int, int>

int k, mn = INT_MAX;

vector<int> sz;

map<int, int> m;

vector<bool> vis;

vector<vector<pii>> v, E;

int dfs_sz(int x, int p = -1) {
    sz[x] = 1;
    for (auto [i, w] : E[x]) {
        if (i != p && !vis[i]) sz[x] += dfs_sz(i, x);
    }

    return sz[x];
}

int ctrd(int x, int p, int n) {
    for (auto [i, w] : E[x]) {
        if (i != p && !vis[i] && sz[i] > (n >> 1)) return ctrd(i, x, n);
    }

    return x;
}

void dfs(int x, int p, int d1, int d2) {
    for (auto [i, w] : E[x]) {
        if (i != p && !vis[i] && w <= k - d2) {
            m[d2 + w] = min((m[d2 + w] ? m[d2 + w] : INT_MAX), d1 + 1);
            dfs(i, x, d1 + 1, d2 + w);
        }
    }
}

void f(int x, int p = -1) {
    int n = dfs_sz(x), c = ctrd(x, p, n);

    vis[c] = true;

    map<int, int> M; M[0] = 0;
    for (auto [i, w] : E[c]) {
        if (vis[i]) continue;

        m = {{w, 1}};
        dfs(i, c, 1, w);

        for (auto i : m) {
            if (M.find(k - i.ff) != M.end()) mn = min(mn, M[k - i.ff] + i.ss);
        }
        for (auto i : m)
            M[i.ff] = min((M[i.ff] ? M[i.ff] : INT_MAX), i.ss);
    }

    for (auto [i, w] : E[c])
        if (!vis[i]) f(i, c);
}

int best_path(int N, int K, int H[][2], int L[]) {
    k = K;
    E.assign(N, {});
    for (int i = 0; i < N - 1; i++) {
        E[H[i][0]].push_back({H[i][1], L[i]});
        E[H[i][1]].push_back({H[i][0], L[i]});
    }

    sz.assign(N, 0);
    vis.assign(N, false);
    f(0);

    return (mn == INT_MAX ? -1 : mn);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2392 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 139 ms 10912 KB Output is correct
20 Correct 138 ms 11088 KB Output is correct
21 Correct 138 ms 11088 KB Output is correct
22 Correct 136 ms 11088 KB Output is correct
23 Correct 60 ms 11344 KB Output is correct
24 Correct 57 ms 11096 KB Output is correct
25 Correct 87 ms 14680 KB Output is correct
26 Correct 62 ms 18268 KB Output is correct
27 Correct 126 ms 17740 KB Output is correct
28 Correct 150 ms 31828 KB Output is correct
29 Correct 154 ms 30804 KB Output is correct
30 Correct 129 ms 17688 KB Output is correct
31 Correct 169 ms 17744 KB Output is correct
32 Correct 139 ms 17760 KB Output is correct
33 Correct 198 ms 16460 KB Output is correct
34 Correct 116 ms 16480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2392 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 139 ms 10912 KB Output is correct
40 Correct 138 ms 11088 KB Output is correct
41 Correct 138 ms 11088 KB Output is correct
42 Correct 136 ms 11088 KB Output is correct
43 Correct 60 ms 11344 KB Output is correct
44 Correct 57 ms 11096 KB Output is correct
45 Correct 87 ms 14680 KB Output is correct
46 Correct 62 ms 18268 KB Output is correct
47 Correct 126 ms 17740 KB Output is correct
48 Correct 150 ms 31828 KB Output is correct
49 Correct 154 ms 30804 KB Output is correct
50 Correct 129 ms 17688 KB Output is correct
51 Correct 169 ms 17744 KB Output is correct
52 Correct 139 ms 17760 KB Output is correct
53 Correct 198 ms 16460 KB Output is correct
54 Correct 116 ms 16480 KB Output is correct
55 Correct 17 ms 3416 KB Output is correct
56 Correct 10 ms 3164 KB Output is correct
57 Correct 93 ms 11364 KB Output is correct
58 Correct 32 ms 11216 KB Output is correct
59 Correct 326 ms 26192 KB Output is correct
60 Correct 723 ms 50260 KB Output is correct
61 Correct 198 ms 19332 KB Output is correct
62 Correct 207 ms 20052 KB Output is correct
63 Correct 240 ms 19868 KB Output is correct
64 Correct 735 ms 29520 KB Output is correct
65 Correct 113 ms 20868 KB Output is correct
66 Correct 481 ms 29732 KB Output is correct
67 Correct 79 ms 21440 KB Output is correct
68 Correct 312 ms 26888 KB Output is correct
69 Correct 274 ms 25100 KB Output is correct
70 Correct 285 ms 26548 KB Output is correct