# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874112 | siewjh | 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"
const int MAXN = 100005;
vector<int> adj[MAXN];
int dp[MAXN][2], conf[MAXN];
int dfs(int x, bool take){
if (dp[x][take] != -1) return dp[x][take];
int ans = 0;
if (take){
ans = conf[x];
for (int nxt : adj[x]) ans += dfs(nxt, 0);
}
else{
for (int nxt : adj[x]) ans += max(dfs(nxt, 1), dfs(nxt, 0));
}
return dp[x][take] = ans;
}
// Find out best sample
int findSample(int n, int confidence[], int host[], int protocol[]){
if (protocol[1] = 0){
for (int i = 1; i < n; i++) adj[host[i]].push_back(i);
for (int i = 0; i < n; i++) conf[i] = confidence[i];x
return max(dfs(0, 0), dfs(1, 0));
}
else if (protocol[1] = 1){
int ans = 0;
for (int i = 0; i < n; i++) ans += confidence[i];
return ans;
}
else{
int ans = 0;
for (int i = 0; i < n; i++) ans = max(ans, confidence[i]);
return ans;
}
}