{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe president of the Ural State University is going to make an 80\u0027th Anniversary party. The university has a hierarchical structure of employees; that is, the supervisor relation forms a tree rooted at the president. In order to make the party fun for all attendees, the president does not want both an employee and his or her immediate supervisor to attend.\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe personnel office has ranked each employee with a conviviality rating. Your task is to make up a guest list with the maximal conviviality rating of the guests.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe first line contains an integer \u003ci\u003eN\u003c/i\u003e that is a number of employees (1 ≤ \u003ci\u003eN\u003c/i\u003e ≤ 6000).\r\nEmployees are numbered by integers in a range from 1 to \u003ci\u003eN\u003c/i\u003e, \r\nEach of the subsequent \u003ci\u003eN\u003c/i\u003e lines contains the conviviality rating of the corresponding employee.\r\nConviviality rating is an integer in a range from −128 to 127. After that the supervisor relation tree goes.\r\nEach line of the tree specification has the form\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par_pre\"\u003e\u003cpre\u003e\u0026lt;L\u0026gt; \u0026lt;K\u0026gt;\r\n\u003c/pre\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003ewhich means that the \u003ci\u003eK\u003c/i\u003e-th employee is an immediate supervisor of \u003ci\u003eL\u003c/i\u003e-th employee. Input is ended with the line\r\n\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par_pre\"\u003e\u003cpre\u003e0 0\r\n\u003c/pre\u003e\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eOutput the maximal total conviviality rating of the guests.\r\n\u003c/div\u003e\u003c/div\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1 3\r\n2 3\r\n6 4\r\n7 4\r\n4 5\r\n3 5\r\n0 0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}