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 <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... |