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) {
int a = 0, b = 0, c = 0, d = 0;
for(pii vt : adj[u]) {
int v = vt.first, t = vt.second;
pii res = recur(v);
int va = res.first, vb = res.second;
if(t == 0) {
a += max(va, vb);
} else {
c = max(c, b + vb);
if(t == 1)
d = max(d, vb - va);
}
b += va;
}
b += conf[u] + d;
return make_pair(a, max(b, c));
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
int cum = 0, i = 1;
while(i < n && host[i] == 0 && protocol[i] == 1)
cum += confidence[i++];
while(i < n) {
adj[host[i]].push_back(make_pair(i, protocol[i]));
i++;
}
conf = confidence;
pii res = recur(0);
return cum + 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... |