Submission #1049538

#TimeUsernameProblemLanguageResultExecution timeMemory
1049538hyakupFriend (IOI14_friend)C++17
100 / 100
20 ms7772 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int inf = 1e9 + 10; vector<pair<int,int>> adj[maxn]; int v[maxn], dp[maxn][2]; void dfs( int cur ){ int sum0 = 0, sum1 = 0, maxi = 0; for( auto [viz, type] : adj[cur] ){ dfs( viz ); if( type == 0 ){ sum0 += dp[viz][1]; sum1 += dp[viz][0]; } if( type == 1 ){ sum0 += dp[viz][0]; sum1 += dp[viz][1]; } if( type == 2 ){ sum0 += dp[viz][0]; sum1 += dp[viz][0]; } maxi = max( maxi, sum1 - sum0 + (( type == 2 ) ? dp[viz][1] - dp[viz][0] : 0 ) ); } dp[cur][1] = max( sum1 + v[cur], maxi + sum0 ); dp[cur][0] = sum0; } int findSample( int n, int confidence[], int host[], int protocol[] ){ for( int i = 0; i < n; i++ ){ v[i] = confidence[i]; if( i ) adj[host[i]].push_back({ i, protocol[i] }); } dfs( 0 ); return dp[0][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...