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> //Andrei Alexandru a.k.a Sho
#include "friend.h"
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
pair<int,int>dp[100005];
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i=0;i<n;i++)
{
dp[i]=mp(0,confidence[i]);
}
for(int i=n-1;i>=1;i--)
{
int par=host[i];
if(protocol[i]==0){
dp[par].f=dp[par].f+dp[i].s;
dp[par].s=dp[par].s+dp[i].f;
}else if(protocol[i]==1){
dp[par].f+=max(dp[i].f,dp[i].s);
dp[par].s+=max(dp[i].f,dp[i].s);
}else {
dp[par].s=max(dp[par].f+dp[i].s,dp[par].s+dp[i].f);
dp[par].f+=dp[i].f;
}
dp[par].s=max(dp[par].s,dp[par].f);
}
return dp[0].s;
}
/*
int32_t main(){
int n=6;
int a[15],b[15],c[15];
a[1]=0;
a[2]=0;
a[3]=1;
a[4]=2;
a[5]=0;
b[0]=13;
b[1]=3;
b[2]=6;
b[3]=20;
b[4]=10;
b[5]=15;
c[1]=0;
c[2]=1;
c[3]=2;
c[4]=1;
c[5]=0;
cout<<findSample(n,b,a,c)<<endl;
}
*/
# | 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... |