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>
#define pb push_back
using namespace std ;
// Find out best sample
const int N = 100010 ;
int confi[N] ;
int dp [N][2];
vector <int> G[N][2] ;
int go ( int u, int flag ) {
auto &rf = dp[u][flag];
if ( rf!=-1 ) return rf ;
if ( flag ) {
///take
int x = confi[u] ;
for ( auto v:G[u][0] ) x += go( v, 0 ) ;
for ( auto v:G[u][1] ) x += go( v, 1 ) ;
rf = x ;
///dont take
x = 0 ;
for ( auto v:G[u][0] ) x += go(v,1 ) ;
for ( auto v:G[u][1] ) x += go(v, 1) ;
rf = max ( rf, x ) ;
}
else {
int x = 0 ;
for ( auto v:G[u][1] ) x += go ( v, 0 ) ;
for ( auto v:G[u][0] ) x += go ( v, 1 ) ;
rf = x ;
}
return rf ;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
for ( int i = 0 ; i < n ; ++i ) confi[i] = confidence[i] ;
for ( int i = 1 ; i < n ; ++i ) G[host[i]][protocol[i]].push_back ( i ) ;
memset ( dp,-1,sizeof dp ) ;
return go(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... |