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>
#ifndef ARTHUR_LOCAL
#include "friend.h"
#endif
using namespace std;
const int MAXN=1000;
int C[MAXN];
int H[MAXN];
int P[MAXN];
vector<int> adj[MAXN];
int ans[2][MAXN];
bool vis[MAXN];
void dfs(int v)
{
vis[v]=1;
// ans[1][v]+=C[v];
for(auto u:adj[v])
{
if(vis[u]) continue;
dfs(u);
ans[0][v] += ans[1][u];
ans[1][v] += ans[0][u];
}
ans[1][v] = max(C[v]+ans[1][v],ans[0][v]);
}
int findSample(int n, int C_raw[], int H_raw[], int P_raw[])
{
for(int i=0; i<n; i++)
{
C[i]=C_raw[i];
H[i]=H_raw[i];
P[i]=P_raw[i];
}
for(int i=1; i<n; i++)
{
adj[i].push_back(H[i]);
adj[H[i]].push_back(i);
}
dfs(0);
return max(ans[0][0], ans[1][0]);
}
# | 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... |