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>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#include "friend.h"
// Find out best sample
/*vector<int> adj[100001];
int vis[100001];
int aa[100001];
int co[2];
void dfs(int no,int levv=0){
co[levv]+=aa[no];
vis[no]=1;
for(auto j:adj[no]){
if(vis[j]==0){
// cout<<no<<","<<j<<endl;
dfs(j,(levv+1)%2);
}
}
}*/
int vis[100001];
vector<int> adj[100001];
int findSample(int n,int it[],int par[],int pp[]){
/*if(n<=10){
for(int i=0;i<n;i++){
adj[i].clear();
}
for(int i=1;i<n;i++){
if(pp[i]==1 or pp[i]==2){
for(auto j:adj[par[i]]){
adj[i].pb(j);
adj[j].pb(i);
}
}
if(pp[i]==0 or pp[i]==2){
adj[i].pb(par[i]);
adj[par[i]].pb(i);
}
}
int ans2=0;
for(int i=0;i<(1<<n);i++){
int st=1;
int su=0;
for(int j=0;j<n;j++){
if((1<<j)&i){
su+=it[j];
vis[j]=1;
}
else{
vis[j]=0;
}
}
for(int j=0;j<n;j++){
if(vis[j]){
for(auto k:adj[j]){
if(vis[k]){
st=0;
}
}
}
}
if(st){
ans2=max(ans2,su);
}
}
return ans2;
}*/
int ma=0;
for(int i=0;i<n;i++){
ma=max(ma,it[i]);
}
/*for(int i=1;i<n;i++){
if(pp[i]==2){
return ma;
}
}*/
int ans=0;
for(int i=n-1;i>=0;i--){
if(i==0){
ans+=it[i];
}
else{
if(pp[i]==1){
it[par[i]]+=it[i];
}
else if(pp[i]==0){
ans+=it[i];
it[par[i]]-=it[i];
if(it[par[i]]<0){
it[par[i]]=0;
}
}
else{
it[par[i]]=max(it[par[i]],it[i]);
}
}
}
return ans;
}
/*int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}*/
/*
g++ -o aa -O2 friend.cpp grader.cpp -std=c++14
*/
/*
2
10 20
0 1
*/
/*2
10 20
0 0
3
1 1 1
0 0 0 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... |