{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"Given a tree (a connected graph with no cycles), you have to find the cost to go to the farthest node from each node. The edges of the tree are weighted and undirected."}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026#8804; 10)**, denoting the number of test cases.\n\nEach case starts with an integer **n (2 \u0026#8804; n \u0026#8804; 30000)** denoting the total number of nodes in the tree. The nodes are numbered from **0** to **n-1**. Each of the next **n-1** lines will contain three integers **u v w (0 \u0026#8804; u, v \u0026lt; n, u \u0026#8800; v, 1 \u0026#8804; w \u0026#8804; 10000)** denoting that node **u** and **v** are connected by an edge whose weight is **w**. You can assume that the input will form a valid tree."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number in a line first. Then for each node (from **0** to **n - 1**) print the cost to go to the farthest node in a separate line."}},{"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\u003e2\n4\n0 1 20\n1 2 30\n2 3 50\n5\n0 2 20\n2 1 10\n0 3 29\n0 4 50\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\n100\n80\n50\n100\nCase 2:\n50\n80\n70\n79\n80\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"MD","content":"Dataset is huge, use faster I/O methods."}}]}