Submission #1027177

#TimeUsernameProblemLanguageResultExecution timeMemory
1027177huutuanFriend (IOI14_friend)C++14
100 / 100
25 ms8196 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int N=1e5+10, inf=1e9; int a[N], f[N][2]; vector<pair<int, int>> g[N]; void dfs(int u){ int ff[2][2]{{0, -inf}, {-inf, -inf}}, gg[2][2]{{-inf, -inf}, {-inf, -inf}}; for (auto &e:g[u]){ int v=e.first, w=e.second; dfs(v); for (int i=0; i<2; ++i) for (int j=0; j<2; ++j){ gg[i][j]=max(gg[i][j], ff[i][j]+f[v][0]); if (w==0) gg[1][j]=max(gg[1][j], ff[i][j]+f[v][1]); if (w==1 && i==0) gg[i][1]=max(gg[i][1], ff[i][j]+f[v][1]); if (w==2 && i==0) gg[1][1]=max(gg[1][1], ff[i][j]+f[v][1]); } for (int i=0; i<2; ++i) for (int j=0; j<2; ++j) ff[i][j]=gg[i][j], gg[i][j]=-inf; } f[u][0]=max(ff[0][0], ff[1][0]); f[u][1]=max(ff[0][1], ff[1][1]); f[u][1]=max(f[u][1], max(ff[0][0], ff[0][1])+a[u]); } // Find out best sample int findSample(int n,int confidence[],int host[],int protocol[]){ for (int i=0; i<n; ++i) a[i]=confidence[i]; for (int i=1; i<n; ++i){ g[host[i]].emplace_back(i, protocol[i]); } dfs(0); return max(f[0][0], f[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...