| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 719336 | Ahmed57 | Friend (IOI14_friend) | C++14 | 0 ms | 0 KiB |
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;
int find_sample(int n,int con[],int host[],int prt[]){
long long dp[n+1][2];
for(int i = 0;i<n;i++){
dp[i][1]=con[i];
dp[i][0]=0;
}
for(int i = n-1;i>=1;i--){
if(prt[i]==0){
dp[host[i]][0]+=dp[i][1];
dp[host[i]][1]+=dp[i][0];
}if(prt[i]==1){
dp[host[i]][1]+=dp[i][1];
dp[host[i]][0]+=dp[i][0];
}if(prt[i]==2){
dp[host[i]][0]+=dp[i][0];
dp[host[i]][1]=max(dp[host[i]][1]+dp[i][0],dp[host[i]][0]+dp[i][1]);
}
dp[host[i]][1] = max(dp[host[i]][1],dp[host[i]][0]);
}
return max(dp[0][1],dp[0][0]);
}
/*signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n = 6;
int host[] = {0,0,0,1,2,0};
int con[] = {13,3,6,20,10,15};
int prt[] = {0,0,1,2,1,0};
cout<<find_sample(n,con,host,prt)<<endl;
}*/
