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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
const int maxn = 1e5 + 5;
int arr[maxn];
vector<int> graph[maxn];
int findSample(int n, int _arr[], int host[], int protocol[]) {
copy(_arr, _arr + n, arr);
for (int i = 1; i < n; i++) {
if (protocol[i] == 0 || protocol[i] == 2) {
graph[i].push_back(host[i]);
}
if (protocol[i] == 1 || protocol[i] == 2) {
graph[i].insert(graph[i].end(), begin(graph[host[i]]),
end(graph[host[i]]));
}
for (auto& a : graph[i]) {
graph[a].push_back(i);
}
}
if (n <= 10) {
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
int cans = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
cans += arr[j];
for (auto& a : graph[j]) {
if ((i >> a) & 1) {
goto loop;
}
}
}
}
ans = max(ans, cans);
loop:;
}
return ans;
}
if (protocol[1] == 1) {
for (auto& a : graph) {
assert(!sz(a));
}
return accumulate(arr, arr + n, 0);
} else if (protocol[1] == 2) {
return *max_element(arr, arr + n);
}
assert(false);
}
# | 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... |