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 <bits/stdc++.h>
#include "friend.h"
using namespace std;
pair<int, int> dfs(int v, vector<vector<int>> &graph, vector<bool> &visited, vector<int> &val) {
if (visited[v]) return {0, 0};
visited[v] = 1;
pair<int, int> res = {val[v], 0};
for (int i: graph[v]) {
pair<int, int> tmp = dfs(i, graph, visited, val);
res.first += tmp.second;
res.second += tmp.first;
}
res.first = max(res.first, res.second);
return res;
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
vector<set<int>> friends(n);
if (n<=10) {
for (int i = 1; i<n; i++) {
int v = host[i];
int type = protocol[i];
// int value = confidence[i];
if (type == 0) {
for (int j = 0; j<i; j++) {
if (j == v) {
friends[i].insert(j);
friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
continue;
}
}
}
if (type == 1) {
for (int j = 0; j<i; j++) {
if (friends[v].count(j)) {
friends[i].insert(j);
friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
continue;
}
}
}
if (type == 2) {
for (int j = 0; j<i; j++) {
if (friends[v].count(j) || j == v) {
friends[i].insert(j);
friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
continue;
}
}
}
}
int res = 0;
for (int i = 0; i<(1<<n); i++) {
int tmp = 0;
vector<int> nodes;
for (int j = 0; j<n; j++) {
if (i & (1<<j)) nodes.push_back(j);
}
bool poss = 1;
for (int i: nodes) {
for (int j: nodes) {
if (friends[i].count(j)) poss = 0;
}
}
if (!poss) continue;
for (int i: nodes) {
tmp += confidence[i];
}
res = max(res, tmp);
}
return res;
}
int res = 0;
if (protocol[1] == 1) {
for (int i = 0; i<n; i++) {
res += confidence[i];
}
}
if (protocol[1] == 2) {
for (int i = 0; i<n; i++) {
res = max(res, confidence[i]);
}
}
if (protocol[1] == 0) {
vector<int> val;
for (int i = 0; i<n; i++) val.push_back(confidence[i]);
vector<vector<int>> graph(n);
for (int i = 1; i<n; i++) {
graph[i].push_back(host[i]);
graph[host[i]].push_back(i);
}
vector<bool> visited(n, 0);
return dfs(0, graph, visited, val).first;
}
return res;
}
# | 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... |