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;
using ll = long long;
using i64 = long long;
void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char* x) { cerr << '"' << x << '"'; } void __print(const string& x) { cerr << '"' << x << '"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#define ln "\n"
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define ar array
int Bit(int mask, int b) { return (mask >> b) & 1; }
const ll base = 311, MOD = 998244353, M = 1e9 + 7, INF = 1e18;
// Find out best sample
int findSample(int n, int confidence[], int host[], int protocol[]) {
int sub = accumulate(protocol + 1, protocol + n, 0);
if (n <= 10) {
bitset<10> adj[10];
rep(i, 0, n - 1) adj[i][i] = true;
rep(i, 1, n - 1) {
if (protocol[i] == 0) {
adj[host[i]][i] = true;
adj[i][host[i]] = true;
}
else if (protocol[i] == 1) {
rep(j, 0, i - 1)
if (adj[host[i]][j] && j != host[i]) {
adj[i][j] = true;
adj[j][i] = true;
}
}
else {
rep(j, 0, i - 1)
if (adj[host[i]][j]) {
adj[i][j] = true;
adj[j][i] = true;
}
}
}
int ans = 0;
for (int s = 1; s < (1 << n); ++s) {
int ok = 1, sum = 0;
rep(i, 0, n - 1) if (s >> i & 1) {
rep(j, 0, n - 1) if (s >> j & 1)
if (i != j && adj[i][j])
ok = false;
sum += confidence[i];
}
if (ok)
ans = max(ans, sum);
}
return ans;
}
else if (sub == 0) { // tree
vector<vector<int>> adj(n);
rep(i, 1, n - 1)
adj[host[i]].push_back(i);
vector<vector<int64_t>> d(n, vector<int64_t>(2));
auto dfs = [&](auto self, int u) -> void {
vector<ar<int64_t, 2>> w;
int64_t sum0 = 0;
for (int v : adj[u]) {
self(self, v);
sum0 += d[v][0];
w.push_back({ d[v][0], d[v][1] });
}
d[u][1] = confidence[u] + sum0;
for (auto [i, j] : w)
d[u][0] += max(i, j);
};
dfs(dfs, 0);
return max(d[0][0], d[0][1]);
}
else if (sub == n - 1) {
return accumulate(confidence, confidence + n, 0);
}
else if (sub == 2 * (n - 1)) {
return *max_element(confidence, confidence + n);
}
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... |