이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int N=100006;
int choose[N],notChoose[N];
int findSample(int n,int value[],int host[],int protocol[]){
for (int i=0;i<n;i++){
choose[i]=value[i];
}
for (int i=n-1;i>0;i--){
int v=host[i];
if (protocol[i]==0){
choose[v]+=notChoose[i];
notChoose[v]+=max(notChoose[i],choose[i]);
}
else if (protocol[i]==1){
choose[v]=max(choose[v]+choose[i],max(choose[v]+notChoose[i],choose[i]+notChoose[v]));
notChoose[v]+=notChoose[i];
}
else{
choose[v]=max(choose[v]+notChoose[i],choose[i]+notChoose[v]);
notChoose[v]+=notChoose[i];
}
//cout<<choose[v]<<" "<<notChoose[v]<<endl;
}
return max(choose[0],notChoose[0]);
}
/*
#define __MAXSIZE__ 100002
// 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;
}
*/
# | 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... |