{"trustable":false,"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":"\u003chtml\u003e\n \u003chead\u003e\u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id\u003d\"problem-body\"\u003e \n \u003ctable class\u003d\"problems\" width\u003d\"100%\"\u003e \n \u003c/table\u003e \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. \u003c/p\u003e \n \u003cp\u003eWe will ask you to perfrom some instructions of the following form:\u003c/p\u003e \n \u003cul\u003e \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 or \u003c/li\u003e \n \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. \u003c/li\u003e \n \u003c/ul\u003e \n \u003ch3\u003eInput\u003c/h3\u003e \n \u003cp\u003eIn the first line there are two integers \u003cb\u003eN\u003c/b\u003e and \u003cb\u003eQ\u003c/b\u003e. \u003c/p\u003e \n \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. \u003c/p\u003e \n \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 \n \u003ch3\u003eOutput\u003c/h3\u003e \n \u003cp\u003eFor each \"\u003cb\u003e1 v\u003c/b\u003e\" operation, write one integer representing its result.\u003c/p\u003e \n \u003ch3\u003eExample\u003c/h3\u003e \n \u003cpre\u003e\n\u003cb\u003eInput:\u003c/b\u003e\n9 8\n1 2\n1 3\n2 4\n2 9\n5 9\n7 9\n8 9\n6 8\n1 3\n0 8\n1 6\n1 7\n0 2\n1 9\n0 2\n1 9 \n\n\u003cb\u003eOutput:\u003c/b\u003e\n-1\n8\n-1\n2\n-1\n\u003c/pre\u003e \n \u003ch3\u003eConstraints \u0026amp; Limits\u003c/h3\u003e \n \u003cp\u003eThere are 12 real input files. \u003c/p\u003e \n \u003cp\u003eFor 1/3 of the test cases, N\u003d5000, Q\u003d400000. \u003c/p\u003e \n \u003cp\u003eFor 1/3 of the test cases, N\u003d10000, Q\u003d300000. \u003c/p\u003e \n \u003cp\u003eFor 1/3 of the test cases, N\u003d100000, Q\u003d100000.\u003c/p\u003e \n \u003c/div\u003e\n \u003c/body\u003e\n\u003c/html\u003e"}}]}