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 N = 1e5 + 10;
int n , ar[N] , dp[N][2];
bool par[N] , prv[N];
vector <int> adj[N];
void Dfs(int v)
{
for(auto u : adj[v])
Dfs(u);
if(adj[v].empty())
{
dp[v][1] = ar[v];
//cout << v << " : " << dp[v][0] << " " << dp[v][1] << endl;
return;
}
int tmp[2];
tmp[0] = tmp[1] = 0;
for(auto u : adj[v])
{
if(prv[u])
tmp[1] = max(tmp[1] + dp[u][0] , tmp[0] + dp[u][1]);
else
tmp[1] += dp[u][1];
tmp[0] += dp[u][0];
}
dp[v][0] = tmp[1];
tmp[0] = tmp[1] = ar[v];
for(auto u : adj[v])
{
if(par[u])
tmp[1] += dp[u][0];
else if(prv[u])
tmp[1] = max(tmp[1] + dp[u][0] , tmp[0] + dp[u][1]);
else
tmp[1] += dp[u][1];
tmp[0] += dp[u][0];
}
dp[v][1] = max(dp[v][0] , tmp[1]);
//cout << v << " : " << dp[v][0] << " " << dp[v][1] << endl;
}
int findSample(int nn,int confidence[],int host[],int protocol[]){
n = nn;
for(int i = 0 ; i < n ; i++)
ar[i] = confidence[i];
int ans = 0;
for(int i = 0 ; i < n ; i++)
ans = max(ans , ar[i]);
return ans;
for(int i = 1 ; i < n ; i++)
{
adj[host[i]].push_back(i);
if(protocol[i] == 0)
par[i] = true;
else if(protocol[i] == 1)
prv[i] = true;
else
{
par[i] = true;
prv[i] = true;
}
}
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... |