{"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 \u003cp\u003eYou are given a tree (an acyclic undirected connected graph) with N nodes. The tree nodes are numbered from 1 to N. We define dist(a, b) as the number of edges on the path from node a to node b. \u003c/p\u003e \n \u003cp\u003eEach node has a color, white or black. All the nodes are black initially. \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\u003e0 i : change the color of i-th node(from black to white, or from white to black). \u003c/li\u003e \n \u003cli\u003e1 \u003cb\u003ev\u003c/b\u003e : ask for the minimum dist(u, \u003cb\u003ev\u003c/b\u003e), node u must be white(u can be equal to \u003cb\u003ev\u003c/b\u003e). Obviously, as long as node \u003cb\u003ev\u003c/b\u003e is white, the result will always be 0. \u003c/li\u003e \n \u003c/ul\u003e \n给出一棵n结点的树,边权为1,一开始每个点颜色都是黑色。\u003cbr\u003e\n现有q个询问,每次询问会有两种操作:\u003cbr\u003e\n1.0 i 改变i的颜色,黑变白,白变黑。\u003cbr\u003e\n2.1 v 询问与v距离最近的白点,显然,当v颜色为白色时,答案是0。\u003cbr\u003e\n \u003ch3\u003eInput\u003c/h3\u003e \n \u003cul\u003e \n \u003cli\u003eIn the first line there is an integer N (N \u0026lt;\u003d 100000) \u003c/li\u003e \n \u003cli\u003eIn the next N-1 lines, the i-th line describes the i-th edge: a line with two integers a b denotes an edge between a and b. \u003c/li\u003e \n \u003cli\u003eIn the next line, there is an integer Q denotes the number of instructions (Q \u0026lt;\u003d 100000) \u003c/li\u003e \n \u003cli\u003eIn the next Q lines, each line contains an instruction \"0 i\" or \"1 \u003cb\u003ev\u003c/b\u003e\" \u003c/li\u003e \n \u003c/ul\u003e \n \u003ch3\u003eOutput\u003c/h3\u003e \n \u003cp\u003eFor each \"1 \u003cb\u003ev\u003c/b\u003e\" operation, print one integer representing its result. If there is no white node in the tree, you should write \"\u003cb\u003e-1\u003c/b\u003e\". \u003c/p\u003e \n \u003ch3\u003eExample\u003c/h3\u003e \n \u003cpre\u003e\n\u003cb\u003eInput:\u003c/b\u003e\n10\n1 2\n1 3\n2 4\n1 5\n1 6\n4 7\n7 8\n5 9\n1 10\n10\n0 6\n0 6\n0 6\n1 3\n0 1\n0 1\n1 3\n1 10\n1 4\n1 6\n\n\u003cb\u003eOutput:\u003c/b\u003e\n2\n2\n2\n3\n0\n\n\u003c/pre\u003e \n \u003c/div\u003e\n \u003c/body\u003e\n\u003c/html\u003e"}}]}