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;
const int N = 1010;
int n, *conf;
bool act[N];
vector<int> G[N];
int solve(int u)
{
if (u == n)
return 0;
bool can = true;
for (auto v : G[u]) if (act[v])
can = false;
int ans = 0;
if (can) {
act[u] = true;
ans = max(ans, conf[u]+solve(u+1));
}
act[u] = false;
ans = max(ans, solve(u+1));
return ans;
}
int dp[N][2];
void dfs(int u, int p)
{
dp[u][1] = conf[u];
for (auto v : G[u]) if (v != p) {
dfs(v, u);
dp[u][0] += max(dp[v][0], dp[v][1]);
dp[u][1] += dp[v][0];
}
}
int findSample(int n, int confidence[], int host[], int protocol[])
{
if (n > 100000) return -1;
::n = n;
conf = confidence;
for (int i = 1; i < n; ++i) {
if (protocol[i] != 0) {
for (auto v : G[host[i]]) {
G[i].push_back(v);
G[v].push_back(i);
}
}
if (protocol[i] != 1) {
G[i].push_back(host[i]);
G[host[i]].push_back(i);
}
}
if (n <= 10)
return solve(0);
if (protocol[1] == 1) {
int sum = 0;
for (int i = 0; i < n; ++i)
sum += conf[i];
return sum;
}
if (protocol[1] == 2) {
int mx = 0;
for (int i = 0; i < n; ++i)
mx = max(mx, conf[i]);
return mx;
}
dfs(0, 0);
return max(dp[0][0], dp[0][1]);
}
# | 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... |