Submission #136154

#TimeUsernameProblemLanguageResultExecution timeMemory
136154arthurconmyFriend (IOI14_friend)C++14
19 / 100
3 ms504 KiB
#include <bits/stdc++.h> #ifndef ARTHUR_LOCAL #include "friend.h" #endif using namespace std; const int MAXN=1000; int C[MAXN]; int H[MAXN]; int P[MAXN]; vector<int> adj[MAXN]; int ans[2][MAXN]; bool vis[MAXN]; void dfs(int v) { vis[v]=1; // ans[1][v]+=C[v]; for(auto u:adj[v]) { if(vis[u]) continue; dfs(u); ans[0][v] += ans[1][u]; ans[1][v] += ans[0][u]; } ans[1][v] = max(C[v]+ans[1][v],ans[0][v]); } int findSample(int n, int C_raw[], int H_raw[], int P_raw[]) { for(int i=0; i<n; i++) { C[i]=C_raw[i]; H[i]=H_raw[i]; P[i]=P_raw[i]; } for(int i=1; i<n; i++) { adj[i].push_back(H[i]); adj[H[i]].push_back(i); } dfs(0); return max(ans[0][0], ans[1][0]); }
#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...