Submission #428323

#TimeUsernameProblemLanguageResultExecution timeMemory
428323DaktoFriend (IOI14_friend)C++17
35 / 100
2 ms460 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> me,friends,we; vector<long long> conf; using dp= pair<pair<long long,long long>,pair<long long, long long>>; vector<dp> res; template<class T> void remax(T& a, T b){if(b>a) a=b;} void dfs(int u){ long long tr=0, nu=0, uu=0; for(auto i:me[u]){ dfs(i); uu+=res[i].first.first; nu+=res[i].second.first; } for(auto i:friends[u]){ dfs(i); uu+=res[i].first.second; nu+=res[i].second.first; } for(auto i:we[u]){ dfs(i); uu+=res[i].first.first; nu+=res[i].second.first; } for(auto i:me[u]){ tr+=res[i].second.second-res[i].second.first; } dp r={{nu,uu+conf[u]},{nu,uu+conf[u]}}; remax(r.first.first,tr+nu); long long mf=0; for(auto i:friends[u]){ remax(r.second.first,res[i].second.second+tr+nu-res[i].second.first); remax(r.second.second,conf[u]+res[i].first.second+nu-res[i].second.first); } for(auto i:we[u]){ remax(r.second.second,res[i].second.second+nu-res[i].second.first); } remax(r.first.second,r.first.first); remax(r.second.first, r.first.first); remax(r.second.second,max(r.first.second,r.second.first)); res[u]=r; } int findSample(int n,int confidence[],int host[],int protocol[]){ me.resize(n); friends.resize(n); we.resize(n); conf.resize(n); res.resize(n); for(int i=0; i<n; i++){ conf[i]=confidence[i]; } for(int i=1; i<n; i++){ if(protocol[i]==0) me[host[i]].push_back(i); if(protocol[i]==1) friends[host[i]].push_back(i); if(protocol[i]==2) we[host[i]].push_back(i); } dfs(0); return res[0].second.second; }

Compilation message (stderr)

friend.cpp: In function 'void dfs(int)':
friend.cpp:36:15: warning: unused variable 'mf' [-Wunused-variable]
   36 |     long long mf=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...