Submission #1107014

#TimeUsernameProblemLanguageResultExecution timeMemory
1107014LucaLucaMCat in a tree (BOI17_catinatree)C++17
0 / 100
2 ms11088 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #warning That's not the baby, that's my baby #define debug(x) #x << " = " << x << '\n' using ll = long long; const int INF = 1e9; const int NMAX = 2e5; std::vector<int> dp[NMAX + 1]; std::vector<int> g[NMAX + 1]; int depth[NMAX + 1]; int deepest[NMAX + 1]; int n, d; void join(std::vector<int> &a, const std::vector<int> &b) { assert((int) a.size() >= (int) b.size()); std::vector<int> c((int) b.size() + 1, 0); for (int i = 0; i < (int) b.size(); i++) { for (int j = 0; j < (int) a.size(); j++) { if (i + j + 1 >= d) { c[std::min(i + 1, j)] = std::max(c[std::min(i + 1, j)], a[j] + b[i]); } } } for (int i = 0; i < (int) c.size(); i++) { a[i] = std::max(a[i], c[i]); } } void dfs(int u) { deepest[u] = depth[u]; int with = -1; for (const auto &v : g[u]) { depth[v] = 1 + depth[u]; dfs(v); if (deepest[v] > deepest[u]) { deepest[u] = deepest[v]; with = v; } } if (with == -1) { // frunza dp[u].resize(1); dp[u][0] = 1; return; } std::swap(dp[u], dp[with]); dp[u].insert(dp[u].begin(), 1); for (const auto &v : g[u]) { if (v != with) { join(dp[u], dp[v]); } } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif std::cin >> n >> d; for (int i = 1; i < n; i++) { int p; std::cin >> p; g[p + 1].push_back(i + 1); } dfs(1); std::cout << *std::max_element(dp[1].begin(), dp[1].end()) << '\n'; return 0; }

Compilation message (stderr)

catinatree.cpp:5:2: warning: #warning That's not the baby, that's my baby [-Wcpp]
    5 | #warning That's not the baby, that's my baby
      |  ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...