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 <vector>
using namespace std;
// Find out best sample
int findSample(int n, int confidence[], int host[], int protocol[]){
vector<int> M(n), NM(n);
for(int i = 0; i < n; i++) {
M[i] = confidence[i];
NM[i] = 0;
}
for(int i = n-1; i > 0; i--) {
// i is person being added
int x = host[i];
int y = i;
if (protocol[i] == 0) {
NM[x] += max(M[y], NM[y]);
M[x] += NM[y];
} else if (protocol[i] == 1) {
// My friends are yours
//int mx = max(NM[x], M[x]) + max(NM[y], M[y]);
int mx = max(M[x] + M[y], max(NM[x] + M[y], NM[y] + M[x]));
int nmx = NM[x] + NM[y];
M[x] = mx;
NM[x] = nmx;
} else if (protocol[i] == 2) {
// We are all friends
int mx = max(NM[x] + M[y], NM[y] + M[x]);
int nmx = NM[x] + NM[y];
M[x] = mx;
NM[x] = nmx;
}
}
return max(M[0], NM[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... |