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 maxn = 1e5 + 10;
const int inf = 1e9 + 10;
vector<pair<int,int>> adj[maxn];
int v[maxn], dp[maxn][2];
void dfs( int cur ){
int sum[2], maxi = 0;
sum[0] = sum[1] = 0;
for( auto [viz, type] : adj[cur] ){
dfs( viz );
for( int t = 0; t < 2; t++ ) sum[t] += dp[viz][(int)(t == type)];
maxi = max( maxi, sum[1] - sum[0] + (( type == 2 ) ? dp[viz][1] - dp[viz][0] : 0 ) );
}
dp[cur][1] = max( sum[1] + v[cur], maxi + sum[0] );
dp[cur][0] = sum[0];
}
int findSample( int n, int confidence[], int host[], int protocol[] ){
for( int i = 0; i < n; i++ ){
v[i] = confidence[i];
if( i ) adj[host[i]].push_back({ i, protocol[i] });
}
dfs( 0 );
return dp[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... |