# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
73887 | funcsr | 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 <vector>
#include <cassert>
#include <tuple>
#include <queue>
#define rep(i, n) for (int i=0; i<(n); i++)
#define pb push_back
using namespace std;
int dp0[100000], dp1[100000];
int findSample(int N, int A[], int host[], int protocol[]) {
rep(i, N) dp0[i] = 0, dp1[i] = A[i];
for (int x=N-1; x>0; x--) {
int p = host[x];
if (protocol[x] == 0) {
dp0[p] += max(dp0[x], dp1[x]);
dp1[p] += dp0[x];
}
else if (protocol[x] == 1) {
dp0[p] += dp0[x];
dp1[p] += max(dp0[x], dp1[x]);
}
else {
dp0[p] += dp0[x];
dp1[p] = max({dp0[x]+dp1[p], dp1[x]+dp0[p], dp0[x]+dp0[p]});
}
}
return max(dp0[0], dp1[0]);
}