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 ll long long
using namespace std;
const int maxn=1e5+5;
int N,niz[maxn],dp[2][maxn];
ll res=0;
vector<int> graf[maxn];
void grana(int a,int b){
graf[a].push_back(b);
graf[b].push_back(a);
}
void dfs(int gde,int pret){
for(int x:graf[gde]){
if(x==pret)
continue;
dfs(x,gde);
dp[0][gde]+=max(dp[1][x],dp[0][x]);
dp[1][gde]+=dp[0][x];
}
dp[1][gde]+=niz[gde];
return;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
N=n;
for(int i=1;i<=N;i++)
niz[i]=confidence[i-1];
for(int i=1;i<N;i++){
int x=host[i]+1;
int p=protocol[i];
if(p==1 or p==2){
for(int aa:graf[x])
grana(aa,i+1);
}
if(p==0 or p==2)
grana(x,i+1);
}
dfs(1,1);
return max(dp[0][1],dp[1][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... |