# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1184577 | Adrian_Soriaga | Friend (IOI14_friend) | C++20 | 0 ms | 0 KiB |
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
int findSample(int n,int confidence[],int host[],int protocol[]){
vector<int> yes(n) , no(n);
for (int i=0; i<n; i++){
yes[i] = confidence[i];
}
for (int i=n-1; i>0; i--){
int cur = host[i];
if (protocol[i] == 0){
yes[cur] += no[i];
no[cur] = max(no[cur]+no[i], no[cur] +yes[i]);
}
else{
if (protocol[i] == 1){
//not including host
yes[cur] = max(yes[cur]+yes[i], max(no[cur]+yes[i], yes[cur]+no[i]));
}
else{
yes[cur] = max(no[cur]+yes[i], yes[cur]+no[i])
}
no[cur] += no[i];
}
}
return max(yes[0],no[0]);
}