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 "grader.cpp"
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 1005;
vector <int> g[N];
int a[N], cn;
void dfs (int v, int color, int &sum, int p = -1) {
if (color)
sum += a[v];
cn++;
for (auto to : g[v]) {
if (to == p) continue;
dfs(to, color ^ 1, sum, v);
}
}
int findSample(int n, int val[], int batya[], int type[]) {
int ans = 0, res = 0;
if (type[1] == 1) {
for (int i = 0; i < n; i++) {
ans += val[i];
}
}
else if (type[1] == 2) {
for (int i = 0; i < n; i++) {
ans = max(ans, val[i]);
}
}
else {
a[0] = val[0];
for (int i = 1; i < n; i++) {
assert(batya[i] < i);
g[batya[i]].pb(i);
g[i].pb(batya[i]);
a[i] = val[i];
}
dfs(0, 0, ans);
assert(cn == n);
dfs(0, 1, res);
ans = max(ans, res);
}
return ans;
}
# | 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... |