{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eYou are given a tree with \u003cvar\u003e\\(N\\)\u003c/var\u003e vertices \u003cvar\u003e\\(1,2,\\ldots,N\\)\u003c/var\u003e, and positive integers \u003cvar\u003e\\(c_1,c_2,\\ldots,c_N\\)\u003c/var\u003e.\r\nThe \u003cvar\u003e\\(i\\)\u003c/var\u003e-th edge in the tree \u003cvar\u003e\\((1 \\leq i \\leq N-1)\\)\u003c/var\u003e connects Vertex \u003cvar\u003e\\(a_i\\)\u003c/var\u003e and Vertex \u003cvar\u003e\\(b_i\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003cp\u003eWe will write a positive integer on each vertex in \u003cvar\u003e\\(T\\)\u003c/var\u003e and calculate our \u003cem\u003escore\u003c/em\u003e as follows:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eOn each edge, write the smaller of the integers written on the two endpoints.\u003c/li\u003e\r\n\u003cli\u003eLet our score be the sum of the integers written on all the edges.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eFind the maximum possible score when we write each of \u003cvar\u003e\\(c_1,c_2,\\ldots,c_N\\)\u003c/var\u003e on one vertex in \u003cvar\u003e\\(T\\)\u003c/var\u003e, and show one way to achieve it. If an integer occurs multiple times in \u003cvar\u003e\\(c_1,c_2,\\ldots,c_N\\)\u003c/var\u003e, we must use it that number of times.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq N \\leq 10000\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq a_i,b_i \\leq N\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq c_i \\leq 10^5\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003eThe given graph is a tree.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(N\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(a_1\\)\u003c/var\u003e \u003cvar\u003e\\(b_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(a_{N-1}\\)\u003c/var\u003e \u003cvar\u003e\\(b_{N-1}\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(c_1\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(c_N\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eUse the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(M\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(d_1\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(d_N\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003cp\u003ewhere \u003cvar\u003e\\(M\\)\u003c/var\u003e is the maximum possible score, and \u003cvar\u003e\\(d_i\\)\u003c/var\u003e is the integer to write on Vertex \u003cvar\u003e\\(i\\)\u003c/var\u003e.\r\n\u003cvar\u003e\\(d_1,d_2,\\ldots,d_N\\)\u003c/var\u003e must be a permutation of \u003cvar\u003e\\(c_1,c_2,\\ldots,c_N\\)\u003c/var\u003e.\r\nIf there are multiple ways to achieve the maximum score, any of them will be accepted.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","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\u003e5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 2 3 4 5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e10\r\n1 2 3 4 5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eIf we write \u003cvar\u003e\\(1,2,3,4,5\\)\u003c/var\u003e on Vertex \u003cvar\u003e\\(1,2,3,4,5\\)\u003c/var\u003e, respectively, the integers written on the four edges will be \u003cvar\u003e\\(1,2,3,4\\)\u003c/var\u003e, for the score of \u003cvar\u003e\\(10\\)\u003c/var\u003e. This is the maximum possible score.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","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\u003e5\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n3141 59 26 53 59\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e197\r\n59 26 3141 59 53\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003e\u003cvar\u003e\\(c_1,c_2,\\ldots,c_N\\)\u003c/var\u003e may not be pairwise distinct.\u003c/p\u003e\u003c/section\u003e\r\n"}}]}