{"raw_statement":[{"iden":"problem statement","content":"Given is a tree with $N$ vertices numbered $1, \\ldots, N$. The $i$\\-th edge connects Vertex $u_i$ and Vertex $v_i$. Additionally, Vertex $i$ has an integer $h_i$ written on it.  \nWe have $K$ pieces, the $i$\\-th of which is initially on Vertex $s_i$. You will repeat the following operation: choose a piece and move it to one of the vertices adjacent to the vertex the piece is currently on. You will end this process when each piece $i$ is on Vertex $t_i$. It is **not** required for each piece $i$ to go along the shortest path from Vertex $s_i$ to Vertex $t_i$.  \nFor an arrangement of the pieces, let its **potential** be the sum of the integers written on the vertices the pieces are on. If multiple pieces are on the same vertex, the integer on that vertex is added the number of times equal to that number of pieces.  \nFind the minimum possible value of the maximum potential during the process, including the initial and final states."},{"iden":"constraints","content":"*   $1 \\leq N,K \\leq 2000$\n*   $1 \\leq u_i,v_i \\leq N$\n*   $1 \\leq h_i \\leq 10^9$\n*   $1 \\leq s_i,t_i \\leq N$\n*   The given graph is a tree."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$h_1$ $h_2$ $\\ldots$ $h_N$\n$u_1$ $v_1$\n$u_2$ $v_2$\n$:$\n$u_{N-1}$ $v_{N-1}$\n$K$\n$s_1$ $t_1$\n$s_2$ $t_2$\n$:$\n$s_K$ $t_K$"},{"iden":"sample input 1","content":"3\n1 3 2\n1 2\n2 3\n2\n1 3\n3 1"},{"iden":"sample output 1","content":"4\n\nWe can make $4$ the maximum potential during the process, as follows:\n\n*   Initially, the potential is $3$.\n*   Move Piece $2$ to Vertex $2$. The potential is now $4$.\n*   Move Piece $2$ to Vertex $1$. The potential is now $2$.\n*   Move Piece $1$ to Vertex $2$. The potential is now $4$.\n*   Move Piece $1$ to Vertex $3$. The potential is now $3$.\n\nThere is no way to make the maximum potential during the process less than $4$, so the answer is $4$."},{"iden":"sample input 2","content":"7\n100 101 1 100 101 1 1000\n1 2\n2 3\n4 5\n5 6\n1 7\n4 7\n2\n1 3\n4 6"},{"iden":"sample output 2","content":"201"},{"iden":"sample input 3","content":"5\n2 1 100 5 6\n1 2\n2 3\n3 4\n3 5\n2\n2 2\n4 5"},{"iden":"sample output 3","content":"101"},{"iden":"sample input 4","content":"4\n1 2 3 100\n1 4\n2 4\n3 4\n9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3"},{"iden":"sample output 4","content":"115"},{"iden":"sample input 5","content":"6\n1 100 1 1 10 1000\n1 2\n2 3\n4 5\n1 6\n4 6\n3\n1 3\n5 5\n5 5"},{"iden":"sample output 5","content":"102"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}