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;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
vi edges[100005];
int dp[100005][2], a[100005], color[100005], one, two, n, exhaustion;
bool pick[15];
void dfs(int x, int p) {
dp[x][1] = a[x];
for (auto y: edges[x]) {
if (y != p) {
dfs(y, x);
dp[x][1] += dp[y][0];
dp[x][0] += max(dp[y][0], dp[y][1]);
}
}
}
void dfs_color(int x, int p, int c) {
if (color[x]) {
assert(c == color[x]);
return;
}
color[x] = c;
if (c == 1) one++;
else two++;
for (auto y: edges[x]) {
if (y != p) {
dfs_color(y, x, 3-c);
}
}
}
int subtask5() {
int res = 0;
FOR(i, 0, n-1) {
if (!color[i]) {
one = two = 0;
dfs_color(i, -1, 1);
res += max(one, two);
}
}
return res;
}
int subtask4() {
dfs(0, -1);
return max(dp[0][0], dp[0][1]);
}
bool connected(int x, int y) {
for (auto it: edges[x]) {
if (it == y) return true;
}
return false;
}
void recur(int x) {
if (x == n) {
bool ok = true;
FOR(i, 0, n-1) {
FOR(j, i+1, n-1) {
if (pick[i] && pick[j] && connected(i, j)) ok = false;
}
}
if (ok) {
int cnt = 0;
FOR(i, 0, n-1) if (pick[i]) cnt += a[i];
exhaustion = max(exhaustion, cnt);
}
return;
}
pick[x] = 0;
recur(x+1);
pick[x] = 1;
recur(x+1);
}
int subtask1() {
recur(0);
return exhaustion;
}
int findSample(int N,int confidence[],int host[],int protocol[]){
n = N;
FOR(i, 0, n-1) a[i] = confidence[i];
FOR(i, 1, n-1) {
if (protocol[i] == 0) {
edges[i].pb(host[i]);
edges[host[i]].pb(i);
} else if (protocol[i] == 1) {
for (auto y: edges[host[i]]) {
edges[i].pb(y);
edges[y].pb(i);
}
} else {
for (auto y: edges[host[i]]) {
edges[i].pb(y);
edges[y].pb(i);
}
edges[i].pb(host[i]);
edges[host[i]].pb(i);
}
}
if (n <= 10) {
return subtask1();
}
if (*max_element(a, a+n) == 1) {
return subtask5();
}
if (protocol[1] == 0) {
return subtask4();
}
if (protocol[1] == 1) {
int sum = 0;
FOR(i, 0, n-1) {
sum += a[i];
}
return sum;
}
return *max_element(a, a+n);
}
# | 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... |