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>
#include "friend.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const ll linf = 1e18;
int dp[N][2];
int findSample(int n, int a[], int p[], int t[]) {
for (int i = 0; i < n; i++) dp[i][0] = a[i];
for (int i = n - 1; i >= 1; i--) {
if (t[i] == 0) {
dp[p[i]][0] += dp[i][1];
dp[p[i]][1] += max(dp[i][0], dp[i][1]);
}
if (t[i] == 1) {
dp[p[i]][0] = max({dp[p[i]][0] + dp[i][1], dp[p[i]][1] + dp[i][0], dp[p[i]][0] + dp[i][0]});
dp[p[i]][1] += dp[i][1];
}
if (t[i] == 2) {
dp[p[i]][0] = max(dp[p[i]][0] + dp[i][1], dp[p[i]][1] + dp[i][0]);
dp[p[i]][1] += dp[i][1];
}
}
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... |