Submission #1084822

# Submission time Handle Problem Language Result Execution time Memory
1084822 2024-09-07T04:33:48 Z _Masum_Billah Race (IOI11_race) C++17
21 / 100
3000 ms 172936 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];
                if (k - b >= 0 and we.find(k - b) != we.end())
                    ans = min(ans, we[k - b] + 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 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5220 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5156 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 2 ms 5156 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5220 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5156 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 2 ms 5156 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5152 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5164 KB Output is correct
22 Correct 5 ms 5468 KB Output is correct
23 Correct 5 ms 5464 KB Output is correct
24 Correct 5 ms 5468 KB Output is correct
25 Correct 4 ms 5468 KB Output is correct
26 Correct 4 ms 5428 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 5 ms 5468 KB Output is correct
29 Correct 4 ms 5420 KB Output is correct
30 Correct 4 ms 5468 KB Output is correct
31 Correct 4 ms 5468 KB Output is correct
32 Correct 5 ms 5468 KB Output is correct
33 Correct 5 ms 5468 KB Output is correct
34 Correct 5 ms 5468 KB Output is correct
35 Correct 5 ms 5464 KB Output is correct
36 Correct 4 ms 5468 KB Output is correct
37 Correct 4 ms 5588 KB Output is correct
38 Correct 5 ms 5644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5220 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5156 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 2 ms 5156 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 201 ms 16896 KB Output is correct
20 Correct 200 ms 16976 KB Output is correct
21 Correct 207 ms 16980 KB Output is correct
22 Correct 183 ms 17152 KB Output is correct
23 Correct 296 ms 17488 KB Output is correct
24 Correct 128 ms 16724 KB Output is correct
25 Correct 191 ms 20308 KB Output is correct
26 Correct 104 ms 22776 KB Output is correct
27 Correct 283 ms 29780 KB Output is correct
28 Correct 2013 ms 91220 KB Output is correct
29 Correct 1613 ms 83284 KB Output is correct
30 Correct 288 ms 29780 KB Output is correct
31 Correct 295 ms 29780 KB Output is correct
32 Correct 330 ms 30032 KB Output is correct
33 Correct 363 ms 28496 KB Output is correct
34 Execution timed out 3057 ms 172936 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5220 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5156 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 2 ms 5156 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5152 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5164 KB Output is correct
22 Correct 5 ms 5468 KB Output is correct
23 Correct 5 ms 5464 KB Output is correct
24 Correct 5 ms 5468 KB Output is correct
25 Correct 4 ms 5468 KB Output is correct
26 Correct 4 ms 5428 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 5 ms 5468 KB Output is correct
29 Correct 4 ms 5420 KB Output is correct
30 Correct 4 ms 5468 KB Output is correct
31 Correct 4 ms 5468 KB Output is correct
32 Correct 5 ms 5468 KB Output is correct
33 Correct 5 ms 5468 KB Output is correct
34 Correct 5 ms 5468 KB Output is correct
35 Correct 5 ms 5464 KB Output is correct
36 Correct 4 ms 5468 KB Output is correct
37 Correct 4 ms 5588 KB Output is correct
38 Correct 5 ms 5644 KB Output is correct
39 Correct 201 ms 16896 KB Output is correct
40 Correct 200 ms 16976 KB Output is correct
41 Correct 207 ms 16980 KB Output is correct
42 Correct 183 ms 17152 KB Output is correct
43 Correct 296 ms 17488 KB Output is correct
44 Correct 128 ms 16724 KB Output is correct
45 Correct 191 ms 20308 KB Output is correct
46 Correct 104 ms 22776 KB Output is correct
47 Correct 283 ms 29780 KB Output is correct
48 Correct 2013 ms 91220 KB Output is correct
49 Correct 1613 ms 83284 KB Output is correct
50 Correct 288 ms 29780 KB Output is correct
51 Correct 295 ms 29780 KB Output is correct
52 Correct 330 ms 30032 KB Output is correct
53 Correct 363 ms 28496 KB Output is correct
54 Execution timed out 3057 ms 172936 KB Time limit exceeded
55 Halted 0 ms 0 KB -