이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> dp0, dp1;
int dfs1(int u, int p, vector<vector<int>>& adj, vector<int>& conf);
int dfs0(int u, int p, vector<vector<int>>& adj, vector<int>& conf) {
if (dp0[u] != -1) return dp0[u];
dp0[u] = 0;
for (int v: adj[u]) {
if (v == p) continue;
dp0[u] += max(dfs0(v, u, adj, conf), dfs1(v, u, adj, conf));
}
return dp0[u];
}
int dfs1(int u, int p, vector<vector<int>>& adj, vector<int>& conf) {
if (dp1[u] != -1) return dp1[u];
dp1[u] = conf[u];
for (int v: adj[u]) {
if (v == p) continue;;
dp1[u] += dfs0(v, u, adj, conf);
}
return dp1[u];
}
int findSample(int n, int confidence[], int host[], int protocol[]) {
vector<vector<int>> adj(n);
for (int i = 1; i < n; ++i) {
adj[host[i]].push_back(i);
adj[i].push_back(host[i]);
}
dp0 = dp1 = vector<int>(n, -1);
vector<int> conf(n);
for (int i = 0; i < n; ++i) conf[i] = confidence[i];
return max(dfs0(0, 0, adj, conf), dfs1(0, 0, adj, conf));
}
# | 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... |