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 "friend.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
using namespace std;
// Find out best sample
int findSample(int n,int w[],int fa[],int p[]){
vector<int> dp(n),dp2(n);
for(int i=n-1;i>=0;i--){
dp[i]=w[i];
}
for(int i=n-1;i>0;i--){
int a=dp[fa[i]],b=dp2[fa[i]];
if(p[i]==0){
dp[fa[i]]+=dp2[i];
dp2[fa[i]]+=max(dp2[i],dp[i]);
}
else if(p[i]==1){
dp[fa[i]]=max({a+dp[i],b+dp[i],a+dp2[i]});
dp2[fa[i]]+=dp2[i];
}
else{
dp[fa[i]]=max(a+dp2[i],b+dp[i]);
dp2[fa[i]]+=dp2[i];
}
}
return max(dp[0],dp2[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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |