Submission #1049539

#TimeUsernameProblemLanguageResultExecution timeMemory
1049539hyakupFriend (IOI14_friend)C++17
100 / 100
20 ms6884 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 sum[2], maxi = 0; sum[0] = sum[1] = 0; for( auto [viz, type] : adj[cur] ){ dfs( viz ); for( int t = 0; t < 2; t++ ) sum[t] += dp[viz][(int)(t == type)]; maxi = max( maxi, sum[1] - sum[0] + (( type == 2 ) ? dp[viz][1] - dp[viz][0] : 0 ) ); } dp[cur][1] = max( sum[1] + v[cur], maxi + sum[0] ); dp[cur][0] = sum[0]; } 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...