#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
using ll = long long;
int findSample(int n, int conf[], int host[], int p[]) {
vector<ll> choose(n), notChoose(n);
for (int i = 0; i < n; ++i) {
choose[i] = conf[i];
notChoose[i] = 0;
}
for (int i = n - 1; i > 0; --i) {
ll hostNode = host[i];
ll newNode = i;
if(p[i] == 0) {
choose[hostNode] = choose[hostNode] + notChoose[newNode];
notChoose[hostNode] = max(notChoose[hostNode] + choose[newNode], notChoose[hostNode] + notChoose[newNode]);
}
else if(p[i] == 1) {
choose[hostNode] = max(max(choose[hostNode] + notChoose[newNode], notChoose[hostNode] + choose[newNode]), choose[hostNode] + choose[newNode]);
notChoose[hostNode] = notChoose[hostNode] + choose[newNode];
}
else {
choose[hostNode] = max(choose[hostNode] + notChoose[newNode], notChoose[hostNode] + choose[newNode]);
notChoose[hostNode] = notChoose[hostNode] + notChoose[newNode];
}
}
return max(choose[0], notChoose[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... |