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>
#include "friend.h"
using namespace std;
const int N = 1e5 + 10;
int ty[N] , n , ar[N] , dp[N][2];
vector <int> adj[N];
void Dfs(int v)
{
for(auto u : adj[v])
Dfs(u);
dp[v][0] = 0;
dp[v][1] = ar[v];
for(int i = adj[v].size() - 1 ; i >= 0 ; i--)
{
auto u = adj[v][i];
if(ty[u] == 1)
{
dp[v][0] += dp[u][1];
dp[v][1] = max(dp[v][0] , dp[v][1] + dp[u][0]);
}
else if(ty[u] == 2)
{
dp[v][0] += dp[u][0];
dp[v][1] += dp[u][1];
}
else
{
dp[v][1] = max(dp[v][0] + dp[u][1] , dp[v][1] + dp[u][0]);
dp[v][0] += dp[u][0];
}
}
}
int findSample(int nn , int confidence[] , int host[] , int protocol[]){
n = nn;
for(int i = 0 ; i < n ; i++)
ar[i] = confidence[i];
for(int i = 1 ; i < n ; i++)
{
adj[host[i]].push_back(i);
ty[i] = protocol[i] + 1;
}
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... |