Submission #70387

#TimeUsernameProblemLanguageResultExecution timeMemory
70387AbelyanFriend (IOI14_friend)C++17
100 / 100
45 ms7084 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...