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/stdc++.h>
#define N 1000005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
#include "friend.h"
#define __MAXSIZE__ 100002
using namespace std;
ll n,m,ar[N],sum,t;
ll v[N],y[N];
// Find out best sample
int findSample(int nn,int confidence[],int host[],int protocol[]){
int ans=10;
n=nn;
// cout<<endl;
// return ans;
fo(i,0,n-1)
v[i]=confidence[i];
for(int i=n-1;i>=1;i--)
{
ll x=host[i];
// cout<<i<<sp<<x<<endl;
// cout<<v[x]<<sp<<y[x]<<sp<<sp<<v[i]<<sp<<y[i]<<endl;
if(protocol[i]==0)
{
v[x]+=y[i];
y[x]=max(y[x]+v[i],y[x]+y[i]);
}
if(protocol[i]==1)
{
ll a=y[x]+v[i];
v[x]=max(v[x]+v[i],v[x]+y[i]);
v[x]=max(a,v[x]);
y[x]=y[x]+y[i];
}
if(protocol[i]==2)
{
v[x]=max(v[x]+y[i],v[i]+y[x]);
y[x]=y[x]+y[i];
}
// cout<<v[x]<<sp<<y[x]<<endl<<endl;
}
return max(v[0],y[0]);
}
// 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: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:31:6: warning: unused variable 'ans' [-Wunused-variable]
int ans=10;
^~~
# | 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... |