제출 #775635

#제출 시각아이디문제언어결과실행 시간메모리
775635alvingogo친구 (IOI14_friend)C++14
100 / 100
28 ms3404 KiB
#include "friend.h" #include <bits/stdc++.h> #define fs first #define sc second using namespace std; // Find out best sample int findSample(int n,int w[],int fa[],int p[]){ vector<int> dp(n),dp2(n); for(int i=n-1;i>=0;i--){ dp[i]=w[i]; } for(int i=n-1;i>0;i--){ int a=dp[fa[i]],b=dp2[fa[i]]; if(p[i]==0){ dp[fa[i]]+=dp2[i]; dp2[fa[i]]+=max(dp2[i],dp[i]); } else if(p[i]==1){ dp[fa[i]]=max({a+dp[i],b+dp[i],a+dp2[i]}); dp2[fa[i]]+=dp2[i]; } else{ dp[fa[i]]=max(a+dp2[i],b+dp[i]); dp2[fa[i]]+=dp2[i]; } } return max(dp[0],dp2[0]); }
#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...