This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "friend.h"
int findSample(int n, int confidence[], int host[], int protocol[]){
if (n <= 10) {
VVI gp(n);
replr(u, 1, n-1) {
int p = host[u];
int prot = protocol[u];
if (prot == 0 || prot == 2) {
gp[u].pb(p);
gp[p].pb(u);
}
if (prot == 1 || prot == 2) {
for (int v : gp[p]) if (v != u) {
gp[u].pb(v);
gp[v].pb(u);
}
}
}
VVI bad(n, VI(n));
rep(u, n) for (int v : gp[u]) bad[u][v] = true;
int maxvalue = 0;
rep(s, (1<<n)) {
VI a;
rep(i, n) if (s & (1<<i)) a.pb(i);
int value = 0;
for (int u : a) for (int v : a) {
if (bad[u][v]) {
goto vat;
}
}
for (int u : a) value += confidence[u];
vat:
setmax(maxvalue, value);
}
return maxvalue;
}
bool ka[3]{};
replr(u, 1, n-1) ka[protocol[u]] = true;
if (!ka[0] && ka[1] && !ka[2]) {
int ans = 0;
rep(u, n) ans += confidence[u];
return ans;
} else if (!ka[0] && !ka[1] && ka[2]) {
int ans = 0;
rep(u, n) setmax(ans, confidence[u]);
return ans;
} else if (ka[0] && !ka[1] && !ka[2]) {
VVI gp(n);
replr(u, 1, n-1) gp[host[u]].pb(u);
VI dp[2];
dp[0] = dp[1] = VI(n);
reprl(u, n-1, 0) {
dp[0][u] = 0;
dp[1][u] = confidence[u];
for (int v : gp[u]) {
dp[0][u] += max(dp[0][v], dp[1][v]);
dp[1][u] += dp[0][v];
}
}
return max(dp[0][0], dp[1][0]);
}
return 0;
}
# | 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... |