This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef LOCAL
#include "friend.h"
#endif // LOCAL
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 1e5 + 5;
ll f[maxn][2];
int findSample(int n,int confidence[],int host[],int protocol[])
{
for(int i = 0; i < n; ++i){
f[i][0] = 0; f[i][1] = confidence[i];
}
for(int i = n - 1; i > 0; --i){
if(protocol[i] == 0){
f[host[i]][1] += f[i][0];
f[host[i]][0] = max(f[host[i]][0] + f[i][1], f[host[i]][0] + f[i][0]);
}
else if(protocol[i] == 1){
f[host[i]][1] = max({f[host[i]][1] + f[i][0],
f[i][1] + f[host[i]][0],
f[host[i]][1] + f[i][1]});
f[host[i]][0] += f[i][0];
}
else{
f[host[i]][1] = max(f[host[i]][1] + f[i][0], f[i][1] + f[host[i]][0]);
f[host[i]][0] += f[i][0];
}
}
return max(f[0][0], f[0][1]);
}
#ifdef LOCAL
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
int n; cin >> n;
int val[n], host[n], type[n + 5];
for(int i = 0; i < n; ++i){
cin >> val[i];
}
for(int i = 1; i < n; ++i){
cin >> host[i] >> type[i];
// cerr << host[i] << ' ' << type[i] << '\n';
}
cout << findSample(n, val, host, type);
}
#endif // LOCAL
# | 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... |