Submission #531851

#TimeUsernameProblemLanguageResultExecution timeMemory
531851StickfishCat in a tree (BOI17_catinatree)C++17
51 / 100
21 ms9616 KiB
#include <iostream> #include <vector> using namespace std; const int MAXN = 1580; vector<int> edg[MAXN]; int depth[MAXN]; int dp[MAXN][MAXN]; signed main() { int n, d; cin >> n >> d; for (int i = 1; i < n; ++i) { int rt; cin >> rt; edg[rt].push_back(i); depth[i] = depth[rt] + 1; } for (int i = n - 1; i >= 0; --i) { dp[i][depth[i]] = 1; if (d + depth[i] < n) { for (auto u : edg[i]) { dp[i][depth[i]] += dp[u][d + depth[i]]; } } for (int t = depth[i] + 1; t < n; ++t) { int d0 = min(n, max(t, depth[i] * 2 + d - t)); int mx = 0; for (auto u : edg[i]) { dp[i][t] += dp[u][d0]; mx = max(mx, dp[u][t] - dp[u][d0]); } dp[i][t] += mx; } for (int t = n - 2; t >= 0; --t) { dp[i][t] = max(dp[i][t], dp[i][t + 1]); } //cout << i << ": "; //for (int j = 0; j < n; ++j) //cout << dp[i][j] << ' '; //cout << '\n'; } cout << dp[0][0] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...