Submission #870349

# Submission time Handle Problem Language Result Execution time Memory
870349 2023-11-07T13:21:07 Z sleepntsheep Cat in a tree (BOI17_catinatree) C++17
0 / 100
2 ms 12636 KB
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <cassert>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using i64 = long long;
#define N 400860

int n, d, h[N], t[N];
vector<int> g[N];
array<int, 2> dp[N];

void upd(int p, int k) { p += 100;for (; p ; p-=p&-p) t[p] += k; }
int qry(int p) { p += 100; int z = 0; for (; p < N; p+=p&-p) z += t[p]; return z; }

void dfs(int u, int p, int dep)
{
    int base = 0, safe = (d+1)/2, sel;

    for (auto v : g[u]) if (v != p) dfs(v, u, dep+1), base += dp[v][0] - 1;

    for (auto v : g[u]) if (v != p) upd(dp[v][1], 1);

    dp[u] = max(dp[u], {base + 1 + qry(d + dep), dep});

    for (auto v : g[u]) if (v != p)
    {
        int delta = dp[v][1] - dep, subdep = dp[v][1];
        upd(dp[v][1], -1);
        sel = base + 1 + qry(dep + max(safe, d - delta));
        upd(dp[v][1], 1);
        dp[u] = max(dp[u], {sel, dep});
    }

    for (auto v : g[u]) if (v != p) upd(dp[v][1], -1);
}

int main()
{
    ShinLena;
    cin >> n >> d;
    for (int i = 1, v; i < n; ++i) cin >> v, g[i].push_back(v), g[v].push_back(i);
    dfs(0, 0, 1);
    cout << dp[0][0];

    return 0;
}


Compilation message

catinatree.cpp: In function 'void dfs(int, int, int)':
catinatree.cpp:36:37: warning: unused variable 'subdep' [-Wunused-variable]
   36 |         int delta = dp[v][1] - dep, subdep = dp[v][1];
      |                                     ^~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -