|
|
back to boardWhy WA#7? Posted by sherry 24 Jul 2008 12:57 #include<stdio.h> #include<stdlib.h> #define max(a,b) a>b? a:b int save[6002],save2[6001]; int boss[6002], l[6002],r[6002],mark[6002],v[6002],used[6002]; long p[6002][2]; int top; int solve() { int i,j,k,c; int x=0,y; if(!save[1])return 0; for(y=1;save[y];y++) { i=save[y]; if(!used[i]) { p[i][1]=v[i]; p[i][1]+=p[l[i]][0]; c=r[l[i]]; while(c) { p[i][1]+=p[c][0]; c=r[c]; } p[i][0]=max(p[l[i]][0],p[l[i]][1]); c=r[l[i]]; while(c) { p[i][0]+=max(p[c][0],p[c][1]); c=r[c]; } save2[++x]=boss[i]; used[i]=1; }
} for(i=1;save[i];i++) { save[i]=save2[i]; } solve(); return 0; }
int main() { int i, j,k; int x,y; int num; scanf("%d",&num); for(i=1;i<=num;i++) scanf("%d",&v[i]); while(scanf("%d%d",&x,&y)==2) { if(!x)break; boss[x]=y; if(l[y]) { r[l[y]]=x;mark[y]=x; } else { l[y]=x;mark[y]=x; } } for(i=1;i<=num;i++) if(!boss[i])break; top=i; j=0; for(i=1;i<=num;i++) if(!l[i]) { save[++j]=boss[i]; p[i][0]=0; p[i][1]=v[i]; } solve(); printf("%ld\n",max(p[top][1],p[top][0])); // system("pause"); return 0; }
Re: Why WA#7? Posted by sherry 24 Jul 2008 12:59 Can 2 poeple supervise 1 person? Re: Why WA#7? Posted by sherry 24 Jul 2008 15:17 I find a mistake yet, so careless~~ a subscrib was miswritten~~~ |
|
|