Submission #834426

# Submission time Handle Problem Language Result Execution time Memory
834426 2023-08-22T14:10:05 Z HaroldVemeno Race (IOI11_race) C++17
100 / 100
664 ms 58368 KB
#include "race.h"
#include <bits/stdc++.h>

#ifdef GUDEB
    #define D(x) cerr << #x << ": " << (x) << '\n';
    #define ifdeb if(true)
#else
    #define D(x) ;
    #define ifdeb if(false)
#endif

#define all(x) begin(x), end(x)

using namespace std;
using ull = unsigned long long;
using ll = long long;
// #define int ll;

struct E {
    int t;
    int w;
};

vector<E> al[200000];
int sts[200000];
bool block[200000];
int n, k;

void calc_sts(int v, int p) {
    if(block[v]) {
        sts[v] = 0;
        return;
    }
    sts[v] = 1;
    for(auto a : al[v]) {
        if(a.t == p) continue;
        calc_sts(a.t, v);
        sts[v] += sts[a.t];
    }
}

int centr_walk(int v) {
    for(auto a : al[v]) {
        if(2*sts[a.t] > sts[v]) {
            sts[v] -= sts[a.t];
            sts[a.t] += sts[v];
            return centr_walk(a.t);
        }
    }
    return v;
}

struct P {
    ll v;
    int l;

    friend bool operator < (const P& a, const P& b) {
        return (a.v < b.v) || (a.v == b.v && a.l < b.l);
    }
};

void paths_dfs(vector<P>& ps, int v, int p, ll d, int l) {
    if(block[v]) return;
    ps.push_back({d, l});
    for(auto a : al[v]) {
        if(a.t == p) continue;
        paths_dfs(ps, a.t, v, d+a.w, l+1);
    }
}

int decomp(int v) {
    if(block[v]) return 2000000;
    calc_sts(v, v);
    v = centr_walk(v);
    set<P> pst;
    pst.insert({0, 0});
    int best = 2000000;
    for(auto a : al[v]) {
        if(block[a.t]) continue;
        vector<P> ps;
        paths_dfs(ps, a.t, v, a.w, 1);
        for(auto p : ps) {
            auto lb = pst.lower_bound({k-p.v, 0});
            if(lb == pst.end()) continue;
            if(lb->v + p.v != k) continue;
            D(lb->v)
            D(lb->l)
            D(p.v)
            D(p.l)
            best = min(best, lb->l+p.l);
        }
        for(auto p : ps) {
            pst.insert(p);
        }
    }
    block[v] = true;
    for(auto a : al[v]) {
        best = min(best, decomp(a.t));
    }
    return best;
}

int best_path(int N, int K, int h[][2], int l[]) {
    n = N; k = K;
    for(int i = 0; i < n-1; ++i) {
        al[h[i][0]].push_back({h[i][1], l[i]});
        al[h[i][1]].push_back({h[i][0], l[i]});
    }
    int r = decomp(0);
    if(r >= 2000000) return -1;
    return r;
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 5200 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 5200 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 5136 KB Output is correct
22 Correct 6 ms 5204 KB Output is correct
23 Correct 3 ms 5204 KB Output is correct
24 Correct 4 ms 5204 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5204 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 3 ms 5204 KB Output is correct
33 Correct 4 ms 5204 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 5200 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 195 ms 13316 KB Output is correct
20 Correct 200 ms 13228 KB Output is correct
21 Correct 191 ms 13524 KB Output is correct
22 Correct 155 ms 12868 KB Output is correct
23 Correct 202 ms 13332 KB Output is correct
24 Correct 95 ms 12680 KB Output is correct
25 Correct 274 ms 29104 KB Output is correct
26 Correct 212 ms 30724 KB Output is correct
27 Correct 234 ms 22220 KB Output is correct
28 Correct 650 ms 58368 KB Output is correct
29 Correct 638 ms 57172 KB Output is correct
30 Correct 281 ms 22220 KB Output is correct
31 Correct 229 ms 22172 KB Output is correct
32 Correct 287 ms 22232 KB Output is correct
33 Correct 364 ms 20648 KB Output is correct
34 Correct 579 ms 40500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 5200 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 5136 KB Output is correct
22 Correct 6 ms 5204 KB Output is correct
23 Correct 3 ms 5204 KB Output is correct
24 Correct 4 ms 5204 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5204 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 3 ms 5204 KB Output is correct
33 Correct 4 ms 5204 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 195 ms 13316 KB Output is correct
40 Correct 200 ms 13228 KB Output is correct
41 Correct 191 ms 13524 KB Output is correct
42 Correct 155 ms 12868 KB Output is correct
43 Correct 202 ms 13332 KB Output is correct
44 Correct 95 ms 12680 KB Output is correct
45 Correct 274 ms 29104 KB Output is correct
46 Correct 212 ms 30724 KB Output is correct
47 Correct 234 ms 22220 KB Output is correct
48 Correct 650 ms 58368 KB Output is correct
49 Correct 638 ms 57172 KB Output is correct
50 Correct 281 ms 22220 KB Output is correct
51 Correct 229 ms 22172 KB Output is correct
52 Correct 287 ms 22232 KB Output is correct
53 Correct 364 ms 20648 KB Output is correct
54 Correct 579 ms 40500 KB Output is correct
55 Correct 17 ms 6612 KB Output is correct
56 Correct 14 ms 5844 KB Output is correct
57 Correct 122 ms 12900 KB Output is correct
58 Correct 38 ms 11708 KB Output is correct
59 Correct 228 ms 31404 KB Output is correct
60 Correct 664 ms 57356 KB Output is correct
61 Correct 269 ms 26336 KB Output is correct
62 Correct 230 ms 22316 KB Output is correct
63 Correct 288 ms 22320 KB Output is correct
64 Correct 635 ms 41284 KB Output is correct
65 Correct 520 ms 41692 KB Output is correct
66 Correct 619 ms 54724 KB Output is correct
67 Correct 90 ms 19520 KB Output is correct
68 Correct 377 ms 37644 KB Output is correct
69 Correct 354 ms 38392 KB Output is correct
70 Correct 324 ms 36420 KB Output is correct