이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#include "friend.h"
using namespace std;
int n,i,f0[100005],f1[100005],c[100005],h[100005],type[100005],u;
int findSample(int n,int c[],int host[],int type[])
{
for(u=0;u<n;u++) f0[u]=0,f1[u]=c[u];
for(i=n-1;i>=1;i--)
{
int v=i,u=host[i],k=type[i];
if(k==0)
{
f1[u]+=f0[v];
f0[u]=f0[u]+max(f0[v],f1[v]);
}
else if(k==1)
{
f1[u]=max(max(f1[u]+f0[v],f0[u]+f1[v]),f1[u]+f1[v]);
f0[u]+=f0[v];
}
else
{
f1[u]=max(f1[u]+f0[v],f0[u]+f1[v]);
f0[u]+=f0[v];
}
}
return max(f0[0],f1[0]);
}
/*
int main()
{
freopen("friend.inp","r",stdin);
freopen("friend.out","w",stdout);
cin>>n;
for(i=0;i<n;i++) cin>>c[i];
for(i=1;i<n;i++) cin>>h[i]>>type[i];
cout<<findSample(n,c,h,type);
}
*/
# | 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... |