{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eA weighted tree is given. You must find the distance between two given nodes.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe first line contains the number of nodes of the tree \u003ci\u003en\u003c/i\u003e (1 ≤ \u003ci\u003en\u003c/i\u003e ≤ 50000). The nodes are numbered from 0 to \u003ci\u003en\u003c/i\u003e\u0026nbsp;–\u0026nbsp;1.\r\nEach of the next \u003ci\u003en\u003c/i\u003e\u0026nbsp;–\u0026nbsp;1 lines contains three integers \r\n\u003ci\u003eu\u003c/i\u003e, \u003ci\u003ev\u003c/i\u003e, \u003ci\u003ew\u003c/i\u003e, which correspond to an edge\r\nwith weight \u003ci\u003ew\u003c/i\u003e (0 ≤ \u003ci\u003ew\u003c/i\u003e ≤ 1000) connecting nodes \u003ci\u003eu\u003c/i\u003e and \u003ci\u003ev\u003c/i\u003e.\r\nThe next line contains the number of queries \u003ci\u003em\u003c/i\u003e (1\u0026nbsp;≤\u0026nbsp;\u003ci\u003em\u003c/i\u003e\u0026nbsp;≤\u0026nbsp;75000).\r\nIn each of the next \u003ci\u003em\u003c/i\u003e lines there are two integers.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eFor each query, output the distance between the nodes with the given numbers.\u003c/div\u003e\u003c/div\u003e"}},{"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\u003e3\r\n1 0 1\r\n2 0 1\r\n3\r\n0 1\r\n0 2\r\n1 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n1\r\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}