Submission #932534

# Submission time Handle Problem Language Result Execution time Memory
932534 2024-02-23T15:20:55 Z LOLOLO Cat in a tree (BOI17_catinatree) C++17
0 / 100
88 ms 139548 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 2e5 + 10;
deque <int> dq[N];
int d;
vector <int> ed[N];

void merge(deque <int> &a, deque <int> &b) {
    for (int i = 0; i < sz(a); i++) {
        if (d - i < sz(b))
            b[i] = max(b[i], a[i] + b[d - i]);         
    }

    for (int i = sz(a) - 2; i >= 0; i--)
        b[i] = max(b[i], b[i + 1]);
}

void dfs(int u) {
    dq[u].push_back(1);
    for (auto x : ed[u]) {
        dfs(x);
        if (sz(dq[u]) < sz(dq[x])) {
            dq[x].push_front(0);
            swap(dq[u], dq[x]);
        } else {
            dq[x].push_front(0);
        }

        merge(dq[x], dq[u]);
    }
}

ll solve() {
    int n;
    cin >> n >> d;
    for (int i = 1; i < n; i++) {
        int x;
        cin >> x;
        ed[x].pb(i);
    }

    dfs(0);

    return dq[0][0];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;

    while (t--) {
        //solve();
        cout << solve() << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 139548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 139548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 139548 KB Output isn't correct
2 Halted 0 ms 0 KB -