# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073702 | Dan4Life | Friend (IOI14_friend) | C++17 | 0 ms | 0 KiB |
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 <algorithm>
int findSample(int n, int c[], int h[], int p[]){
int ans = 0, i; // Mind-blown!
for(int i = n; i>0; i--){
if(p[i]==2) c[h[i]]=max(c[h[i]],c[i]);
else if(p[i]==1) c[h[i]]+=c[i];
else ans+=c[i], c[h[i]]=max(0, c[h[i]]-c[i]);
}
return c[0]+ans;
}