This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#if defined(ONPC) && !defined(_GLIBCXX_ASSERTIONS)
#define _GLIBCXX_ASSERTIONS
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())
#include "friend.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K>
using ordered_set = pd::tree<K, pd::null_type, less<int>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T>
using gp_hash_table = pd::gp_hash_table<T...>;//simple using statement gives warnings
const int INF = 1e9;
const ll INFL = 1e18;
const int N = 1e5;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
bool adj[1000][1000];
memset(adj, 0, sizeof(adj));
for (int i = 1; i < n; i++) {
if (protocol[i] == 0) {
adj[host[i]][i] = 1;
adj[i][host[i]] = 1;
}
else {
for (int j = 0; j < i; j++) {
if (j == host[i] && protocol[i] == 1) continue;
adj[i][j] = 1;
adj[j][i] = 1;
}
}
}
ll dp[n][2];
memset(dp, -1, sizeof(dp));
function<ll(int,int,int)> dfs = [&](int i, int prev, int p) {
if (dp[i][prev] != -1) return dp[i][prev];
ll res = 0;
ll res2 = confidence[i];
for (int e = 0; e < n; e++) {
if (!adj[i][e] || e == p) continue;
res += dfs(e, 0, i);
res2 += dfs(e, 1, i);
}
if (prev == 0) res = max(res, res2);
return dp[i][prev] = res;
};
return dfs(0, 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... |