Submission #974173

#TimeUsernameProblemLanguageResultExecution timeMemory
974173KasymKCat in a tree (BOI17_catinatree)C++17
0 / 100
1 ms3420 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; vector<int> adj[MAXN]; bool marked[MAXN]; int dp[MAXN][2]; void dfs(int node, int parent) { dp[node][0] = 0; dp[node][1] = 1; for (int child : adj[node]) { if (child == parent) continue; dfs(child, node); dp[node][0] += max(dp[child][0], dp[child][1]); dp[node][1] += dp[child][0]; } } int main() { int n, d; cin >> n >> d; for (int i = 1; i < n; i++) { int parent; cin >> parent; adj[parent].push_back(i); } dfs(0, -1); cout << max(dp[0][0], dp[0][1]) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...