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 <iostream>
#include <vector>
// Find out best sample
using namespace std;
int what[100005];
vector < int > Next[100005];
bool have[5][100005]={0};
int DP[5][100005]={0};
int how[100005];
int F(int x,int y,int fa)
{
if(have[x][y]) return DP[x][y];
have[x][y]=1;
for(auto i:Next[y])
{
if(i==fa) continue;
if(x==0) DP[x][y]+=max(F(0,i,y),F(1,i,y));
else DP[x][y]+=F(0,i,y);
}
if(x==1) DP[x][y]+=how[y];
return DP[x][y];
}
int findSample(int n,int confidence[],int host[],int protocol[])
{
int ans=0,i,x=0,y=0;
what[0]=0;
x+=confidence[0];
if(protocol[1]==1) ans+=confidence[0];
if(protocol[1]==0)
{
for(i=0;i<n;i++) how[i]=confidence[i];
for(i=1;i<n;i++)
{
Next[host[i]].push_back(i);
Next[i].push_back(host[i]);
}
return max(F(0,0,-1),F(1,0,-1));
}
else
{
for(i=1;i<n;i++)
{
if(protocol[i]==1) ans+=confidence[i];
else ans=max(ans,confidence[i]);
}
}
return max(max(x,y),ans);
}
# | 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... |