# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1184292 | jcolada | Friend (IOI14_friend) | C++20 | 0 ms | 0 KiB |
#include "friend.h"
#include<bits/stdc++.h>
using namespace std;
int findSample(int n, int confidence[], int host[], int protocol[]){
int cost[n], tot = 0; for(int i = 0; i < n; i++) cost[i] = confidence[i];
for(int i = n-1; i > 0, i--){
if(protocol[i] == 2){cost[host[i]] = max(cost[host[i]],cost[i]);}
else if(protocol[i] == 1){cost[host[i]] += cost[i];}
else{
tot += cost[i];
cost[host[i]] -= min(cost[host[i]], cost[i]);
}
}
tot += cost[0];
return tot;
}