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 <iostream>
#include <vector>
#include <cassert>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define INF 1145141919
#define _1 first
#define _2 second
int N;
int A[100000];
vector<int> G[100000];
long long dp[100000][2];
void dfs(int x) {
long long a = 0, b = A[x];
for (int t : G[x]) {
dfs(t);
a += dp[t][1];
b += dp[t][0];
}
dp[x][0] = a;
dp[x][1] = max(a, b);
}
int findSample(int n, int confidence[], int host[], int protocol[]){
N = n;
rep(i, N) A[i] = confidence[i];
long long m = 0;
if (N <= 10) {
for (int i=1; i<N; i++) {
if (protocol[i] == 0) {
G[host[i]].pb(i);
G[i].pb(host[i]);
}
else if (protocol[i] == 1) {
for (int t : G[host[i]]) G[i].pb(t), G[t].pb(i);
}
else {
for (int t : G[host[i]]) G[i].pb(t), G[t].pb(i);
G[host[i]].pb(i);
G[i].pb(host[i]);
}
}
rep(S, 1<<N) {
bool good = true;
rep(i, N) if ((S>>i)&1) {
for (int t : G[i]) if ((S>>t)&1) {
good = false;
break;
}
}
if (!good) continue;
long long s = 0;
rep(i, N) if ((S>>i)&1) s += A[i];
m = max(m, s);
}
}
else {
for (int i=1; i<N; i++) {
if (protocol[i] != 0) abort();
G[host[i]].pb(i);
}
dfs(0);
m = dp[0][1];
}
return m;
}
# | 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... |