# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
253226 | aZvezda | 친구 (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 "friend.h"
// Find out best sample
const int MAX_N = 1e6 + 10;
int dp[MAX_N];
int findSample(int n, int confidence[], int host[], int protocol[]){
for(int i = 0; i < n; i ++) {
dp[i] = confidence[i];
}
for(int i = n - 1; i > 0; i --) {
if(protocol[i] == 1) {
dp[host[i]] -= min(dp[i], dp[host[i]])
ans += dp[i];
} else if(protocol[i] == 2) {
dp[host[i]] += dp[i];
} else {
if(dp[i] > dp[host[i]]) {
dp[host[i]] = dp[i];
}
}
}
return ans + dp[0];
}