This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |