# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586528 | SeDunion | 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 "friend.h"
#include<iostream>
#include<assert.h>
#include<vector>
using namespace std;
const int N = 1e5 + 123;
int p[N], q[N];
int findSample(int n,int confidence[],int host[],int protocol[]){
for (int i = 0 ; i < n ; ++ i) {
p[i] = confidence[i];
q[i] = 0;
}
for (int y = n - 1 ; y > 0 ; -- y) {
int x = host[y];
if (protocol[y] == 0) {
int np = p[x] + q[y];
int nq = max(q[x] + p[y], q[x] + q[y]);
p[x] = np, q[x] = nq;
} else if (protocol[y] == 1) {
int np = max({p[x] + p[y], p[x] + q[y], q[x] + p[y]});
int nq = q[x] + q[y];
p[x] = np, q[x] = nq;
} else {
int np = max(p[x] + q[y], q[x] + p[y]);
int nq = q[x] + q[y];
p[x] = np, q[x] = nq;
}
}
return max(p[0], q[0]);
}