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 N=1e5+10, inf=1e9;
int a[N], f[N][2];
vector<pair<int, int>> g[N];
void dfs(int u){
int ff[2][2]{{0, -inf}, {-inf, -inf}}, gg[2][2]{{-inf, -inf}, {-inf, -inf}};
for (auto &e:g[u]){
int v=e.first, w=e.second;
dfs(v);
for (int i=0; i<2; ++i) for (int j=0; j<2; ++j){
gg[i][j]=max(gg[i][j], ff[i][j]+f[v][0]);
if (w==0) gg[1][j]=max(gg[1][j], ff[i][j]+f[v][1]);
if (w==1 && i==0) gg[i][1]=max(gg[i][1], ff[i][j]+f[v][1]);
if (w==2 && i==0) gg[1][1]=max(gg[1][1], ff[i][j]+f[v][1]);
}
for (int i=0; i<2; ++i) for (int j=0; j<2; ++j) ff[i][j]=gg[i][j], gg[i][j]=-inf;
}
f[u][0]=max(ff[0][0], ff[1][0]);
f[u][1]=max(ff[0][1], ff[1][1]);
f[u][1]=max(f[u][1], max(ff[0][0], ff[0][1])+a[u]);
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
for (int i=0; i<n; ++i) a[i]=confidence[i];
for (int i=1; i<n; ++i){
g[host[i]].emplace_back(i, protocol[i]);
}
dfs(0);
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... |