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;
#define SZ 666666
int val[SZ],fa[SZ],fe[SZ];
vector<int> so[SZ];
int f[SZ][2][2];
inline void cmax(int&a,int b)
{if(a<b)a=b;}
void dfs(int x)
{
int ts[2][2][2];
memset(ts,-127/2,sizeof ts);
ts[0][0][0]=0;
ts[0][1][0]=val[x];
ts[1][0][0]=0;
// cout<<fa[x]<<"->"<<x<<":"<<fe[x]<<" "<<val[x]<<"\n";
for(auto ch:so[x])
{
dfs(ch);
int g[2][2][2];
memset(g,-127/2,sizeof g);
if(fe[ch]==0)
{
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
for(int c=0;c<2;++c)
{
cmax(g[a][b][c],ts[a][b][c]+f[ch][b][0]);
if(!b)
cmax(g[a][b][1],ts[a][b][c]+f[ch][b][1]);
}
}
else if(fe[ch]==1)
{
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
for(int c=0;c<2;++c)
{
cmax(g[a][b][c],ts[a][b][c]+f[ch][a||c][0]);
if(!a&&!c)
cmax(g[a][1][c],ts[a][b][c]+f[ch][0][1]);
}
}
else if(fe[ch]==2)
{
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
for(int c=0;c<2;++c)
{
cmax(g[a][b][c],ts[a][b][c]+f[ch][a||b||c][0]);
if(!a&&!c&&!b)
cmax(g[a][1][c],ts[a][b][c]+f[ch][0][1]);
}
}
memcpy(ts,g,sizeof g);
}
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
f[x][a][b]=max(ts[a][b][0],ts[a][b][1]);
}
int findSample(int n,int confidence[],
int host[],int protocol[]){
for(int i=0;i<n;++i) val[i]=confidence[i];
for(int i=1;i<n;++i)
fa[i]=host[i],fe[i]=protocol[i],
so[host[i]].push_back(i);
dfs(0);
return max(f[0][0][1],f[0][0][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... |