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>
#define ll long long
#define pb push_back
using namespace std;
const ll N = 1e6 + 10;
ll p[N], q[N];
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i = 0; i < n; i++)
p[i] = confidence[i];
for(int i = n - 1; i > 0; i--) {
if(protocol[i] == 0) {
// 1
p[host[i]] = p[host[i]] + q[i];
q[host[i]] = max(q[host[i]] + p[i], q[host[i]] + q[i]);
} else if(protocol[i] == 1) {
// withfriends
p[host[i]] = max({p[host[i]] + q[i], p[host[i]] + p[i], q[host[i]] + p[i]});
q[host[i]] = q[host[i]] + q[i];
} else {
p[host[i]] = max({p[host[i]] + q[i], q[host[i]] + p[i]});
q[host[i]] = q[host[i]] + q[i];
}
}
return max(p[0], q[0]);
}
/*
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
6 13 3 6 20 10 15 0 0 0 1 1 2 2 1 0 0
*/
/*
#define __MAXSIZE__ 100002
#include "friend.h"
using namespace std;
// Confidence
int confidence[__MAXSIZE__];
// Host
int host[__MAXSIZE__];
// Protocol
int protocol[__MAXSIZE__];
// Main
int main(void)
{
int n,i;
// Number of people
assert(scanf("%d",&n)==1);
// Confidence
for(i=0;i<n;i++)
assert(scanf("%d",&confidence[i])==1);
// Host and Protocol
for(i=1;i<n;i++)
assert(scanf("%d %d",&host[i],&protocol[i])==2);
// Answer
printf("%d\n",findSample(n,confidence,host,protocol));
return 0;
}
/**/
Compilation message (stderr)
friend.cpp:71:1: warning: "/*" within comment [-Wcomment]
71 | /**/
|
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:12:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
12 | for(int i = 0; i < n; i++)
| ^~~
friend.cpp:14:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
14 | for(int i = n - 1; i > 0; i--) {
| ^~~
# | 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... |