# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702070 | PCTprobability | Friend (IOI14_friend) | C++17 | 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>
//#include "friend.h"
using namespace std;
using ll = long long;
#define pb push_back
vector<int> g[100000];
int dp[100000][2];
ll con[100000];
void dfs(int a,int b){
for(auto e:g[a]){
if(e==b) continue;
dfs(e,a);
dp[a][0]+=max(dp[e][0],dp[e][1]);
dp[a][1]+=dp[e][0];
}
dp[a][1]+=con[a];
dp[a][1]=max(dp[a][1],dp[a][0]);
}
int findSample(int n, vector<int> confidence, vector<int> host, vector<int> protocol){
for(int i=0;i<n;i++) con[i]=confidence[i];
for(int i=n-1;i>=1;i--){
assert(host[i]<i);
dp[i][1]+=con[i];
dp[i][1]=max(dp[i][1],dp[i][0]);
if(protocol[i]==0){
dp[host[i]][0]+=dp[i][1];
dp[host[i]][1]+=dp[i][0];
}
if(protocol[i]==1){
dp[host[i]][0]+=dp[i][0];
dp[host[i]][1]+=dp[i][1];
}
if(protocol[i]==2){
}
}
dp[0][1]+=con[0];
return max(dp[0][1],dp[0][0]);
}
int main(){
int n;
cin>>n;
vector<int> confidence(n);
for(int i=0;i<n;i++) cin>>confidence[i];
vector<int> host(n),protocol(n);
for(int i=0;i<n;i++) cin>>host[i]>>protocol[i];
cout<<findSample(6,{10,1,1,1,50,100},{0,0,0,0,0,0},{0,1,1,1,1,1})<<endl;
}