# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874102 | theghostking1 | Friend (IOI14_friend) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "friend.h"
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
bool istree = true;
for (int i = 0; i<n; i++){
if (protocol[i] != 0) istree = false;
}
if (istree){
//root the tree
//use stack to dfs
stack<pair<int,pair<int,int>>> s;
vector<bool> vis(n);
vector<int> col(n);
s.push({0,0,-1});
while (!s.empty()){
pair<int,int> a = s.top();
s.pop();
int node = a.first;
int prev = a.second.second;
int flag = a.second.first;
col[node] = flag;
vis[node] = true;
for (auto u : adj[node]){
if (u == prev) continue;
s.push({u,{1-flag,node}});
}
}
int one = 0;
int zero = 0;
for (int i = 0; i<n; i++){
if (col[i] == 0){
zero += confidence[i];
}
else{
one += confidence[i];
}
}
return max(one,zero);
}
return ans;
}