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"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
constexpr int MAXN = 100000;
vector<pii> adj[MAXN + 2];
int *conf;
pii recur(int u, bool k) {
int a = 0, b = 0, c = 0, d = 0;
for(pii vt : adj[u]) {
int v = vt.first, t = vt.second;
k &= t == 1;
pii res = recur(v, k);
int va = res.first, vb = res.second, mvab = max(va, vb);
if(k) {
a += mvab;
b += mvab;
continue;
}
k = false;
if(t == 0) {
a += mvab;
} else {
c = max(c, b + vb);
if(t == 1)
d = max(d, vb - va);
}
b += va;
}
b += conf[u] + d;
//cout << "? " << u << ' ' << a << ' ' << max(b, c) << endl;
return make_pair(a, max(b, c));
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i = 1; i < n; i++)
adj[host[i]].push_back(make_pair(i, protocol[i]));
conf = confidence;
pii res = recur(0, true);
return max(res.first, res.second);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |