Submission #404167

#TimeUsernameProblemLanguageResultExecution timeMemory
404167biggFriend (IOI14_friend)C++14
35 / 100
19 ms2824 KiB
#include "friend.h" #include<bits/stdc++.h> using namespace std; // Find out best sample const int MAXN = 1e5 + 10; vector<int> grafo[MAXN]; int dp[MAXN][5], v[MAXN], comp[MAXN], maxc[MAXN]; void dfsc(int x, int p, int c){ comp[x] = c; for(int v : grafo[x]){ if(v == p) continue; dfsc(v, x, c); } } void dfs(int x, int p){ dp[x][0] = 0, dp[x][1] = v[x]; for(int v : grafo[x]){ if(v == p) continue; dfs(v, x); dp[x][0] += max(dp[v][0], dp[v][1]); dp[x][1] += dp[v][0]; } } int findSample(int n,int confidence[],int host[],int protocol[]){ int ans= 0; if(protocol[1] == 1){ for(int i = 0; i < n; i++) ans += confidence[i]; return ans; } if(protocol[1] == 2){ for(int i = 0; i < n; i++) ans = max(ans, confidence[i]); return ans; } for(int i = 0; i < n; i++) v[i] = confidence[i]; for(int i = 1; i < n; i++){ grafo[host[i]].push_back(i); grafo[i].push_back(host[i]); } int c = 0; for(int i = 0; i < n; i++){ if(!comp[i]){ dfsc(i,i, ++c); } } for(int i = 0; i < n; i++){ dfs(i, i); maxc[comp[i]] = max(maxc[comp[i]], dp[i][1]); } for(int i = 1; i <= c; i++) ans += maxc[i]; return ans; }
#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...