{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relation forms a tree rooted at the rector V. E. Tretyakov. In order to make the party funny for every one, the rector does not want both an employee and his or her immediate supervisor to be present. The personnel office has evaluated conviviality of each employee, so everyone has some number (rating) attached to him or her. Your task is to make a list of guests with the maximal possible sum of guests\u0027 conviviality ratings. \n \u003cbr\u003e \n\u003c/div\u003e\n\u003cbr\u003e \n\u003cbr\u003e有个公司要举行一场晚会。为了让到会的每个人不受他的直接上司约束而能玩得开心,公司领导决定:如果邀请了某个人,那么一定不会再邀请他的直接的上司,但该人的上司的上司,上司的上司的上司……都可以邀请。已知每个人最多有唯一的一个上司。\n\u003cbr\u003e已知公司的每个人参加晚会都能为晚会增添一些气氛,求一个邀请方案,使气氛值的和最大。"}},{"title":"Input","value":{"format":"HTML","content":"Employees are numbered from 1 to N. A first line of input contains a number N. 1 \u0026lt;\u003d N \u0026lt;\u003d 6 000. Each of the subsequent N lines contains the conviviality rating of the corresponding employee. Conviviality rating is an integer number in a range from -128 to 127. After that go T lines that describe a supervisor relation tree. Each line of the tree specification has the form: \n\u003cbr\u003eL K \n\u003cbr\u003eIt means that the K-th employee is an immediate supervisor of the L-th employee. Input is ended with the line \n\u003cbr\u003e0 0\n\u003c\u003e\n\u003cbr\u003e注意包含多组输入\n\u003cbr\u003e第1行一个整数N表示公司的人数。\n\u003cbr\u003e接下一行N个整数。第i行的数表示第i个人的气氛值x(-128\u003c\u003dx\u003c\u003d127)\n\u003cbr\u003e接N-1下来每行两个整数L,K。表示第K个人是第L个人的上司。\n\u003cbr\u003e输入以两个0结尾"}},{"title":"Output","value":{"format":"HTML","content":"Output should contain the maximal sum of guests\u0027 ratings. \n\u003cbr\u003e\n一个数,最大的气氛值和。"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e7\n1\n1\n1\n1\n1\n1\n1\n1 3\n2 3\n6 4\n7 4\n4 5\n3 5\n0 0\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e5\u003c/pre\u003e"}}]}