{"trustable":false,"sections":[{"title":"","value":{"format":"MD","content":"A tree is a connected graph with no cycle. Given a tree with weighted and undirected edges, you have to find the farthest nodes in the tree. In other words, you have to find two nodes in the tree whose distance is maximum amongst all nodes."}},{"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**. The input will form a valid tree."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number and the maximum distance."}},{"title":"Sample","value":{"format":"MD","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: 100\nCase 2: 80\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."}}]}