{"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\r\n\u003ctable class\u003d\"problems\" width\u003d\"100%\"\u003e\u003ctbody\u003e\u003ctr class\u003d\"navigation\"\u003e\r\n\u003ctd width\u003d\"50%\"\u003e\u003ca href\u003d\"https://www.spoj.com/problems/QTREE3/en/\"\u003eEnglish\u003c/a\u003e\u003c/td\u003e \r\n\u003ctd width\u003d\"50%\"\u003e\u003ca href\u003d\"https://www.spoj.com/problems/QTREE3/vn/\"\u003eVietnamese\u003c/a\u003e\u003c/td\u003e \r\n\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\r\n\r\n\r\n\u003cp\u003eYou are given a tree (an acyclic undirected connected graph) with N nodes. The tree nodes are numbered from 1 to N. In the start, the color of any node in the tree is white.\r\n\u003c/p\u003e\u003cp\u003eWe will ask you to perfrom some instructions of the following form:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cb\u003e0 i\u003c/b\u003e : change the color of the i-th node (from white to black, or from black to white);\u003cbr\u003e\r\nor\r\n\u003c/li\u003e\u003cli\u003e\u003cb\u003e1 v\u003c/b\u003e : ask for the id of the first black node on the path from node 1 to node v. if it doesn\u0027t exist, you may return -1 as its result.\r\n\u003c/li\u003e\u003c/ul\u003e\r\n\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eIn the first line there are two integers \u003cb\u003eN\u003c/b\u003e and \u003cb\u003eQ\u003c/b\u003e.\r\n\u003c/p\u003e\u003cp\u003eIn the next \u003cb\u003eN\u003c/b\u003e-1 lines describe the edges in the tree: a line with two integers \u003cb\u003ea b\u003c/b\u003e denotes an edge between \u003cb\u003ea\u003c/b\u003e and \u003cb\u003eb\u003c/b\u003e.\r\n\u003c/p\u003e\u003cp\u003eThe next \u003cb\u003eQ\u003c/b\u003e lines contain instructions \u003cb\u003e\"0 i\"\u003c/b\u003e or \u003cb\u003e\"1 v\"\u003c/b\u003e (1 ≤ i, v ≤ N). \u003c/p\u003e\r\n\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003eFor each \"\u003cb\u003e1 v\u003c/b\u003e\" operation, write one integer representing its result.\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\u003e9 8\r\n1 2\r\n1 3\r\n2 4\r\n2 9\r\n5 9\r\n7 9\r\n8 9\r\n6 8\r\n1 3\r\n0 8\r\n1 6\r\n1 7\r\n0 2\r\n1 9\r\n0 2\r\n1 9 \r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\r\n8\r\n-1\r\n2\r\n-1\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\u003ch3\u003eConstraints \u0026amp; Limits\u003c/h3\u003e\r\n\u003cp\u003eThere are 12 real input files.\r\n\u003c/p\u003e\u003cp\u003eFor 1/3 of the test cases, N\u003d5000, Q\u003d400000.\r\n\u003c/p\u003e\u003cp\u003eFor 1/3 of the test cases, N\u003d10000, Q\u003d300000.\r\n\u003c/p\u003e\u003cp\u003eFor 1/3 of the test cases, N\u003d100000, Q\u003d100000.\u003c/p\u003e\r\n\r\n\n\u003c/div\u003e"}}]}