이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
memset(dp, -1, sizeof(dp));
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... |