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 <bits/stdc++.h>
using namespace std;
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];
return max(dfs(0, 0), dfs(0, 1));
}
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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |