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;
int answer = 0;
vector<int> adj[1005];
int dp_get[1005], dp_didnt_get[1005];
void dp (int current, int parent, int confidence[]) {
dp_get[current] = confidence[current];
bool leaf = 1;
for (int x : adj[current]) {
if (x == parent) continue;
leaf = 0;
dp(x, current, confidence);
}
if (leaf) return;
for (int x : adj[current]) {
if (x == parent) continue;
dp_get[current] += dp_didnt_get[x];
dp_didnt_get[current] += max(dp_didnt_get[x], dp_get[x]);
}
}
int findSample(int n, int confidence[],int host[],int protocol[]){
for (int i = 1; i < n; i++) {
if (protocol[i] == 1 || protocol[i] == 2) {
for (int x : adj[host[i]]) {
adj[x].push_back(i);
adj[i].push_back(x);
}
}
if (protocol[i] == 0 || protocol[i] == 2) {
adj[i].push_back(host[i]);
adj[host[i]].push_back(i);
}
}
if (n <= 10) {
for (int i = 0; i < (1<<n); i++) {
vector<int> group;
bool found_connectedness = 0;
for (int j = 0; j < n; j++) {
if (i & (1<<j)) group.push_back(j);
}
for (int i : group) {
for (int j : group) {
for (int x : adj[i]) if ( x == j) found_connectedness = 1;
}
}
if (found_connectedness == 1) continue;
int sum = 0;
for (int x : group) sum += confidence[x];
answer = max(answer, sum);
}
return answer;
}
bool all0 = 1, all1 = 1, all2 = 1;
for (int i = 1; i < n; i++) {
if (protocol[i] == 0) {
all1 = 1;
all2 = 2;
}
if (protocol[i] == 1) {
all1 = 0;
all2 = 2;
}
if (protocol[i] == 2) {
all1 = 0;
all2 = 1;
}
}
if (all1 == 1) {
int sum = 0;
for (int i = 0; i < n; i++) sum += confidence[i];
return sum;
}
if (all2 == 1) {
int ma = 0;
for (int i = 0; i < n; i++) ma = max(ma, confidence[i]);
return ma;
}
if (all0 == 1) {
dp(0, -1, confidence);
return max(dp_get[0], dp_didnt_get[0]);
}
}
Compilation message (stderr)
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:87:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |