Submission #1016336

#TimeUsernameProblemLanguageResultExecution timeMemory
1016336parsadox2Friend (IOI14_friend)C++17
100 / 100
23 ms7004 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; const int N = 1e5 + 10; int ty[N] , n , ar[N] , dp[N][2]; vector <int> adj[N]; void Dfs(int v) { for(auto u : adj[v]) Dfs(u); dp[v][0] = 0; dp[v][1] = ar[v]; for(int i = adj[v].size() - 1 ; i >= 0 ; i--) { auto u = adj[v][i]; if(ty[u] == 1) { dp[v][0] += dp[u][1]; dp[v][1] = max(dp[v][0] , dp[v][1] + dp[u][0]); } else if(ty[u] == 2) { dp[v][0] += dp[u][0]; dp[v][1] += dp[u][1]; } else { dp[v][1] = max(dp[v][0] + dp[u][1] , dp[v][1] + dp[u][0]); dp[v][0] += dp[u][0]; } } } int findSample(int nn , int confidence[] , int host[] , int protocol[]){ n = nn; for(int i = 0 ; i < n ; i++) ar[i] = confidence[i]; for(int i = 1 ; i < n ; i++) { adj[host[i]].push_back(i); ty[i] = protocol[i] + 1; } 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...