Submission #951889

#TimeUsernameProblemLanguageResultExecution timeMemory
951889inkvizytorCat in a tree (BOI17_catinatree)C++11
100 / 100
40 ms12504 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, d; cin >> n >> d; vector<vector<int>> g (n); vector<int> o (n, 0); for (int i = 1; i < n; i++) { int x; cin >> x; g[x].push_back(i); o[i] = x; } vector<pair<int, int>> dp (n, make_pair(0, 1000000)); for (int i = n-1; i >= 0; i--) { int s = 0, naj = 1000000; for (int v : g[i]) { if (dp[v].first > 0) { if (naj+dp[v].second >= d) { s += dp[v].first; naj = min(naj, dp[v].second); } else { s += dp[v].first-1; naj = max(naj, dp[v].second); } } } if (naj >= d) { dp[i] = make_pair(s+1, 1); } else { dp[i] = make_pair(s, naj+1); } } cout << dp[0].first; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...