Submission #1064605

#TimeUsernameProblemLanguageResultExecution timeMemory
1064605NemanjaSo2005Friend (IOI14_friend)C++17
19 / 100
40 ms65536 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...