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>
typedef long long ll;
using namespace std;
#define pb push_back
const int nax = 1e5;
int dp[nax+5][2];
int c[nax+5];
vector<int> adj[nax+5];
int n;
int f(int u, int b) {
int &ret = dp[u][b];
if(~ret) return ret;
ret = 0;
if(adj[u].size() == 0) {
ret = b ? c[u] : 0;
} else {
int a = 0, g = 0;
for(int v : adj[u]) {
a += f(v, 1);
if(b) {
g += f(v, 0);
}
}
if(b) g += c[u];
ret = max(a, g);
}
//cout << u << " " << b << " " << ret << endl;
return ret;
}
// Find out best sample
int findSample(int N,int confidence[],int host[],int protocol[]){
n = N;
memset(dp, -1, sizeof dp);
c[0] = confidence[0];
for(int i=1; i<N; i++) {
//cout << i << " " << host[i] << endl;
c[i] = confidence[i];
adj[host[i]].pb(i);
}
return max(f(0,0), f(0,1));
}
# | 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... |