"CODEVS1380" has no boss's prom.

Source: Internet
Author: User

Description

Ural University has a staff of N and is numbered 1~n. They have affiliation, which means that their relationship is like a tree rooted in the headmaster, and the parent node is the direct boss of the child node. Each employee has a happiness index. There is now an anniversary party, which asks the staff to have the most happiness index. However, no staff is willing to attend with the direct boss.

Input

The first line is an integer n. (1<=n<=6000)
Next n lines, line i+1 represents the happiness index RI for staff i. ( -128<=ri<=127)
Next N-1 line, enter a pair of integer l, K for each line. Indicates that K is the direct boss of L.
Last line input 0, 0.

Output

Output the maximum happiness index.

Sample Input

7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0

Sample Output

5

HINT

Each test point 1s

#include <iostream>using namespacestd;intl[6010]={0};//determine the root nodeintv[6010]={0};intfc[6010];intf[6010][2];structpoitype{intNext,ch;} poi[6010]; intCur=0, N,CH,FA;//cur is the total number of edgesvoidInsertintChintFa//Insert an edge{    ++cur; poi[cur].ch=ch;//number of the sonPOI[CUR].NEXT=FC[FA];//if FC[FA] has a value, FA appears two times, that is, CH has brothers, so next is the brother of CHfc[fa]=cur;}voiddpintX//0 indicates no participation, 1 indicates participation{f[x][0]=0; f[x][1]=V[x];  for(inti=fc[x];i!=0; i=Poi[i].next) {        intNe=poi[i].ch;        DP (NE); f[x][1]+=f[ne][0];//subordinates are not involved .f[x][0]=f[x][0]+max (f[ne][1],f[ne][0]); }}intMain () {CIN>>N;  for(intI=1; i<=n;i++) cin>>V[i];  while(Cin>>ch>>fa &&ch) {L[ch]++;    Insert (CH,FA); }     for(intI=1; i<=n;i++)    {        if(l[i]==0) {DP (i); cout<<max (f[i][0],f[i][1]);  Break; }     }    return 0;}

"CODEVS1380" has no boss's prom.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.