{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e 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","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003e\r\nYou are given a tree (an undirected acyclic connected graph) with \u003cb\u003eN\u003c/b\u003e nodes, and edges numbered 1, 2, 3 ...\u003cb\u003eN\u003c/b\u003e-1. Each edge has an integer value assigned to it, representing its length.\r\n\u003c/p\u003e\r\n\u003cp\u003e\r\nWe will ask you to perform some instructions of the following form:\r\n\u003c/p\u003e\r\n\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cb\u003eDIST a b\u003c/b\u003e : ask for the distance between node \u003cb\u003ea\u003c/b\u003e and node \u003cb\u003eb\u003c/b\u003e\u003cbr\u003e\r\nor\r\n\u003c/li\u003e\u003cli\u003e\u003cb\u003eKTH a b k\u003c/b\u003e : ask for the \u003cb\u003ek\u003c/b\u003e-th node on the path from node \u003cb\u003ea\u003c/b\u003e to node \u003cb\u003eb\u003c/b\u003e \r\n\u003c/li\u003e\u003c/ul\u003e\r\n\r\n\u003cp\u003e\r\n\u003cb\u003eExample:\u003c/b\u003e\u003cbr\u003e\r\n\u003cb\u003eN\u003c/b\u003e \u003d 6 \u003cbr\u003e\r\n1 2 1 // edge connects node 1 and node 2 has cost 1 \u003cbr\u003e\r\n2 4 1 \u003cbr\u003e\r\n2 5 2 \u003cbr\u003e\r\n1 3 1 \u003cbr\u003e\r\n3 6 2 \u003cbr\u003e\r\n\u003cbr\u003e\r\nPath from node 4 to node 6 is 4 → 2 → 1 → 3 → 6 \u003cbr\u003e\r\n\u003cb\u003eDIST 4 6\u003c/b\u003e : answer is 5 (1 + 1 + 1 + 2 \u003d 5) \u003cbr\u003e\r\n\u003cb\u003eKTH 4 6 4\u003c/b\u003e : answer is 3 (the 4-th node on the path from node 4 to node 6 is 3) \u003cbr\u003e\r\n\u003c/p\u003e\r\n\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003e\r\nThe first line of input contains an integer \u003cb\u003et\u003c/b\u003e, the number of test cases (\u003cb\u003et\u003c/b\u003e \u0026lt;\u003d 25). \u003cb\u003et\u003c/b\u003e test cases follow.\r\n\u003c/p\u003e\u003cp\u003eFor each test case:\u003c/p\u003e \r\n\u003cul\u003e\r\n\u003cli\u003eIn the first line there is an integer \u003cb\u003eN\u003c/b\u003e (\u003cb\u003eN\u003c/b\u003e \u0026lt;\u003d 10000)\r\n\u003c/li\u003e\u003cli\u003eIn the next \u003cb\u003eN\u003c/b\u003e-1 lines, the i-th line describes the i-th edge: a line with three integers \u003cb\u003ea b c\u003c/b\u003e denotes an edge between \u003cb\u003ea\u003c/b\u003e, \u003cb\u003eb\u003c/b\u003e of cost \u003cb\u003ec\u003c/b\u003e (\u003cb\u003ec\u003c/b\u003e \u0026lt;\u003d 100000)\r\n\u003c/li\u003e\u003cli\u003eThe next lines contain instructions \u003cb\u003e\"DIST a b\"\u003c/b\u003e or \u003cb\u003e\"KTH a b k\"\u003c/b\u003e\r\n\u003c/li\u003e\u003cli\u003eThe end of each test case is signified by the string \"\u003cb\u003eDONE\u003c/b\u003e\".\r\n\u003c/li\u003e\u003c/ul\u003e\r\n\u003cp\u003eThere is one blank line between successive tests.\r\n\u003c/p\u003e\r\n\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003eFor each \u003cb\u003e\"DIST\"\u003c/b\u003e or \u003cb\u003e\"KTH\"\u003c/b\u003e operation, write one integer representing its result.\u003c/p\u003e\r\n\u003cp\u003ePrint one blank line after each test.\r\n\u003c/p\u003e\r\n\r\n\u003ch3\u003eExample\u003c/h3\u003e\r\n\r\n\u003cdiv\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e1\r\n\r\n6\r\n1 2 1\r\n2 4 1\r\n2 5 2\r\n1 3 1\r\n3 6 2\r\nDIST 4 6\r\nKTH 4 6 4\r\nDONE\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\r\n3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\r\n\n\u003c/div\u003e"}}]}