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 kN = 1007;
vector<int> adj[kN];
pair<int, bool> dp[kN][2];
int solve(int u, bool can, int parent, int confidence[]){
if(dp[u][can].second)
return dp[u][can].first;
dp[u][can].second = true;
int &ans = dp[u][can].first;
ans = 0;
if(can){
int curr_ans = confidence[u];
for(int to: adj[u]){
if(to == parent)
continue;
curr_ans += solve(to, false, u, confidence);
}
ans = max(ans, curr_ans);
}
int curr_ans = 0;
for(int to: adj[u]){
if(to == parent)
continue;
curr_ans += solve(to, true, u, confidence);
}
ans = max(ans, curr_ans);
return ans;
}
int findSample(int n, int confidence[], int host[], int protocol[]){
for(int i = 1; i < n; ++i){
adj[host[i]].push_back(i);
adj[i].push_back(host[i]);
}
return solve(0, true, -1, confidence);
}
# | 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... |