Submission #99286

#TimeUsernameProblemLanguageResultExecution timeMemory
99286dndhkFriend (IOI14_friend)C++14
100 / 100
106 ms8388 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int MAX_N = 100000; vector<pii> gp[MAX_N+1]; int N; int c[MAX_N+1]; pii p[MAX_N+1]; int dp[MAX_N+1][2]; void dfs(int x){ dp[x][1] = c[x]; for(int j = gp[x].size()-1; j>=0; j--){ pii i = gp[x][j]; dfs(i.first); if(i.second==2){ dp[x][1] = max(dp[x][1] + dp[i.first][0], dp[x][0] + max(dp[i.first][1], dp[i.first][0])); dp[x][0] += dp[i.first][0]; }else if(i.second==1){ dp[x][1] += max(dp[i.first][1], dp[i.first][0]); dp[x][1] = max(dp[x][1], dp[x][0] + max(dp[i.first][1], dp[i.first][0])); dp[x][0] += dp[i.first][0]; }else{ dp[x][0] += max(dp[i.first][1], dp[i.first][0]); dp[x][1] += dp[i.first][0]; } } } int findSample(int n, int confidence[], int host[], int protocol[]){ N = n; for(int i=0; i<N; i++){ c[i] = confidence[i]; if(i!=0) { p[i] = {host[i], protocol[i]}; gp[host[i]].push_back({i, protocol[i]}); } } dfs(0); return max(dp[0][0], 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...