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>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2e5+5;
int n,arr[mxn],ans=0,p[mxn],q[mxn];
vector<int>vt[mxn];
int findSample(int N,int confidence[],int host[],int protocol[]){
n=N;
for(int i=0;i<n;i++){
arr[i+1]=confidence[i];
}
for(int i=1;i<=n;i++){
p[i]=arr[i];
q[i]=0;
}
for(int i=n-1;i>=1;i--){
int u=host[i]+1;
int type=protocol[i];
int v=i+1;
if(type==0){
p[u]=p[u]+q[v];
q[u]=max(q[u]+p[v],q[u]+q[v]);
}
else if(type==1){
p[u]=max({p[u]+p[v],p[u]+q[v],q[u]+p[v]});
q[u]=q[u]+q[v];
}
else{
p[u]=max(p[u]+q[v],q[u]+p[v]);
q[u]=q[u]+q[v];
}
}
return max(p[1],q[1]);
}
/*
g++ friend.cpp grader.cpp ; .\a.exe
6
13 3 6 20 10 15
0 0
0 1
1 2
2 1
0 0
6
1 1 1 1 1 1
0 0
0 0
1 0
1 0
1 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... |