#include <bits/stdc++.h>
using namespace std;
#include "friend.h"
int findSample(int n, int c[],int h[],int t[]){
vector<array<int,2>> dp(n);
for (int i=0; i<n; i++) dp[i][0] = 0, dp[i][1] = c[i];
for (int i=n-1; i>0; i--) {
int p = h[i];
if (t[i] == 0) {
dp[p][0] = dp[p][0] + max(dp[i][0], dp[i][1]);
dp[p][1] = dp[p][1] + dp[i][0];
}
if (t[i] == 1) {
dp[p][1] = max(max(dp[p][1] + dp[i][0], dp[p][0] + dp[i][1]), dp[p][1] + dp[i][1]);
dp[p][0] = dp[p][0] + dp[i][0];
}
if (t[i] == 2) {
dp[p][1] = max(dp[p][1] + dp[i][0], dp[p][0] + dp[i][1]);
dp[p][0] = dp[p][0] + dp[i][0];
}
}
return max(dp[0][0], dp[0][1]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |