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 <algorithm>
#include <vector>
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
std::vector < std::vector < int > > d(n, std::vector < int > (2, 0));
for (int i = 0; i < n; i++)
d[i][1] = confidence[i];
for (int i = n - 1; i > 0; i--) {
int x = host[i];
if (protocol[i] == 0) {
d[x][0] += std::max(d[i][1], d[i][0]);
d[x][1] += d[i][0];
} else if (protocol[i] == 1) {
d[x][1] = std::max(std::max(d[x][1] + d[i][1], d[x][1] + d[i][0]), d[x][0] + d[i][1]);
d[x][0] += d[i][0];
} else {
d[x][1] = std::max(d[x][0] + d[i][1], d[x][1] + d[i][0]);
d[x][0] += d[i][0];
}
}
return std::max(d[0][1], d[0][0]);
}
# | 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... |