Submission #1084824

# Submission time Handle Problem Language Result Execution time Memory
1084824 2024-09-07T04:38:49 Z _Masum_Billah Race (IOI11_race) C++17
21 / 100
3000 ms 168600 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const ll N = 2e5 + 10;
vector<array<ll, 2>> ad[N];
ll mark[N], sz[N], ans = 1e18, k;
array<ll, 2> nodes[N];
int t, tin[N], tout[N], lv[N];
map <ll, ll> we;

ll size(ll node, ll par) {
    sz[node] = 1;
    for (auto [v, w] : ad[node]) {
        if (v != par and !mark[v]) {
            sz[node] += size(v, node);
        }
    }
    return sz[node];
}

ll centroid(ll node, ll par, ll s) {
    for (auto [v, w] : ad[node]) {
        if (v != par and !mark[v]) {
            if (sz[v] > s / 2) return centroid(v, node, s);
        }
    }
    return node;
}
void dfs(ll node, ll par, ll wt, int l = 0) {
    nodes[t] = {node, wt};
    tin[node] = t++;
    lv[node] = l;
    for (auto [v, w] : ad[node]) {
        if (v != par and !mark[v]) {
            dfs(v, node, wt + w, l + 1);
        }
    }
    tout[node] = t - 1;
}

void go(ll node) {
    ll s = size(node, node);
    ll c = centroid(node, node, s);
    mark[c] = 1;
    t = 0;
    dfs(c, c, 0);

    for (int i = 0; i < t; i++) {
        auto [a, b] = nodes[i];
        we[b] = 1e18;
    }
    we[0] = 0;
    for (auto [v, w] : ad[c]) {
        if (!mark[v]) {
            for (ll i = tin[v]; i <= tout[v]; i++) {
                auto [a, b] = nodes[i];
                auto it = we.find(k - b);
                if (k - b >= 0 and it != we.end())
                    ans = min(ans, (*it).second + lv[a]);
            }
            for (ll i = tin[v]; i <= tout[v]; i++) {
                auto [a, b] = nodes[i];
                we[b] = min(we[b], 1ll * lv[a]);
            }
        }
    }
    for (int i = 0; i < t; i++) {
        auto [a, b] = nodes[i];
        we[b] = 1e18;
    }

    for (auto [v, w] : ad[c]) {
        if (!mark[v]) {
            go(v);
        }
    }
}

int best_path(int n, int d, int H[][2], int dis[]) {
    k = d;
    for (int i = 0; i + 1 < n; i++) {
        ad[H[i][0]].push_back({H[i][1], dis[i]});
        ad[H[i][1]].push_back({H[i][0], dis[i]});
    }
    go(0);
    if (ans == 1e18) ans = -1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 2 ms 5212 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 4 ms 5176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 2 ms 5212 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 4 ms 5176 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5164 KB Output is correct
21 Correct 3 ms 5212 KB Output is correct
22 Correct 5 ms 5468 KB Output is correct
23 Correct 5 ms 5468 KB Output is correct
24 Correct 4 ms 5468 KB Output is correct
25 Correct 5 ms 5468 KB Output is correct
26 Correct 4 ms 5464 KB Output is correct
27 Correct 3 ms 5212 KB Output is correct
28 Correct 5 ms 5468 KB Output is correct
29 Correct 6 ms 5428 KB Output is correct
30 Correct 5 ms 5464 KB Output is correct
31 Correct 5 ms 5468 KB Output is correct
32 Correct 5 ms 5468 KB Output is correct
33 Correct 6 ms 5468 KB Output is correct
34 Correct 5 ms 5468 KB Output is correct
35 Correct 5 ms 5468 KB Output is correct
36 Correct 5 ms 5468 KB Output is correct
37 Correct 5 ms 5468 KB Output is correct
38 Correct 5 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 2 ms 5212 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 4 ms 5176 KB Output is correct
19 Correct 214 ms 17108 KB Output is correct
20 Correct 197 ms 17028 KB Output is correct
21 Correct 193 ms 16980 KB Output is correct
22 Correct 185 ms 16980 KB Output is correct
23 Correct 317 ms 17864 KB Output is correct
24 Correct 127 ms 16716 KB Output is correct
25 Correct 189 ms 20216 KB Output is correct
26 Correct 113 ms 22808 KB Output is correct
27 Correct 300 ms 29776 KB Output is correct
28 Correct 2032 ms 91200 KB Output is correct
29 Correct 1895 ms 83280 KB Output is correct
30 Correct 327 ms 29776 KB Output is correct
31 Correct 292 ms 29884 KB Output is correct
32 Correct 365 ms 29972 KB Output is correct
33 Correct 396 ms 28752 KB Output is correct
34 Execution timed out 3035 ms 168600 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 2 ms 5212 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 4 ms 5176 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5164 KB Output is correct
21 Correct 3 ms 5212 KB Output is correct
22 Correct 5 ms 5468 KB Output is correct
23 Correct 5 ms 5468 KB Output is correct
24 Correct 4 ms 5468 KB Output is correct
25 Correct 5 ms 5468 KB Output is correct
26 Correct 4 ms 5464 KB Output is correct
27 Correct 3 ms 5212 KB Output is correct
28 Correct 5 ms 5468 KB Output is correct
29 Correct 6 ms 5428 KB Output is correct
30 Correct 5 ms 5464 KB Output is correct
31 Correct 5 ms 5468 KB Output is correct
32 Correct 5 ms 5468 KB Output is correct
33 Correct 6 ms 5468 KB Output is correct
34 Correct 5 ms 5468 KB Output is correct
35 Correct 5 ms 5468 KB Output is correct
36 Correct 5 ms 5468 KB Output is correct
37 Correct 5 ms 5468 KB Output is correct
38 Correct 5 ms 5468 KB Output is correct
39 Correct 214 ms 17108 KB Output is correct
40 Correct 197 ms 17028 KB Output is correct
41 Correct 193 ms 16980 KB Output is correct
42 Correct 185 ms 16980 KB Output is correct
43 Correct 317 ms 17864 KB Output is correct
44 Correct 127 ms 16716 KB Output is correct
45 Correct 189 ms 20216 KB Output is correct
46 Correct 113 ms 22808 KB Output is correct
47 Correct 300 ms 29776 KB Output is correct
48 Correct 2032 ms 91200 KB Output is correct
49 Correct 1895 ms 83280 KB Output is correct
50 Correct 327 ms 29776 KB Output is correct
51 Correct 292 ms 29884 KB Output is correct
52 Correct 365 ms 29972 KB Output is correct
53 Correct 396 ms 28752 KB Output is correct
54 Execution timed out 3035 ms 168600 KB Time limit exceeded
55 Halted 0 ms 0 KB -