{"raw_statement":[{"iden":"problem statement","content":"The Kingdom of AtCoder is composed of $N$ towns and $N-1$ roads.  \nThe towns are labeled as Town $1$, Town $2$, $\\dots$, Town $N$. Similarly, the roads are labeled as Road $1$, Road $2$, $\\dots$, Road $N-1$. Road $i$ connects Towns $A_i$ and $B_i$ bidirectionally, and you have to pay the toll of $C_i$ to go through it. For every pair of different towns $(i, j)$, it is possible to go from Town $A_i$ to Town $B_j$ via the roads.\nYou are given a sequence $D = (D_1, D_2, \\dots, D_N)$, where $D_i$ is the cost to do sightseeing in Town $i$. Let us define the travel cost $E_{i,j}$ from Town $i$ to Town $j$ as the total toll incurred when going from Town $i$ to Town $j$, plus $D_{j}$.\n\n*   More formally, $E_{i,j}$ is defined as $D_j + \\displaystyle\\sum_{l=0}^{k-1} c_l$, where the shortest path between $i$ and $j$ is $i = p_0, p_1, \\dots, p_{k-1}, p_k = j$ and the toll for the road connecting Towns $p_{l}$ and $p_{l+1}$ is $c_l$.\n\nFor every $i$, find the maximum possible travel cost when traveling from Town $i$ to another town.\n\n*   More formally, for every $i$, find $\\max_{1 \\leq j \\leq N, j \\neq i} E_{i,j}$."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq A_i \\leq N$ $(1 \\leq i \\leq N-1)$\n*   $1 \\leq B_i \\leq N$ $(1 \\leq i \\leq N-1)$\n*   $1 \\leq C_i \\leq 10^9$ $(1 \\leq i \\leq N-1)$\n*   $1 \\leq D_i \\leq 10^9$ $(1 \\leq i \\leq N)$\n*   It is possible to travel from Town $i$ to Town $j$ via some number of roads, for a pair of integers $(i,j)$ such that $1 \\leq i \\lt j \\leq N$.\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $B_1$ $C_1$\n$A_2$ $B_2$ $C_2$\n$\\vdots$\n$A_{N-1}$ $B_{N-1}$ $C_{N-1}$\n$D_1$ $D_2$ $\\dots$ $D_N$"},{"iden":"sample input 1","content":"3\n1 2 2\n2 3 3\n1 2 3"},{"iden":"sample output 1","content":"8\n6\n6\n\nThe value of $E_{i,j}$ for every ordered pair of towns $(i,j)$ is as follows.\n\n*   $E_{1,2} = 2 + 2 = 4$\n*   $E_{1,3} = 5 + 3 = 8$\n*   $E_{2,1} = 2 + 1 = 3$\n*   $E_{2,3} = 3 + 3 = 6$\n*   $E_{3,1} = 5 + 1 = 6$\n*   $E_{3,2} = 3 + 2 = 5$"},{"iden":"sample input 2","content":"6\n1 2 3\n1 3 1\n1 4 4\n1 5 1\n1 6 5\n9 2 6 5 3 100"},{"iden":"sample output 2","content":"105\n108\n106\n109\n106\n14"},{"iden":"sample input 3","content":"6\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n1 2 3 4 5 6"},{"iden":"sample output 3","content":"5000000006\n4000000006\n3000000006\n3000000001\n4000000001\n5000000001"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}