{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"现在,给你一棵树,让你去求对于某个点u,\"深度优先搜索\"k次以后的点是哪个点,如果没有,输出-1。\"深度优先搜索\"定义如下:假设当前位于节点a,首先找到a编号最小的子节点b,向b传达指令。然后对b进行同样的操作。直到以b为根的整棵子树都受到命令。然后返回a,再寻找除b外编号最小的子节点。不断重复这个过程。"}},{"title":"Input","value":{"format":"HTML","content":"第一行2个整数n,q,(2 \u003c\u003d n \u003c\u003d 2*10^5, 1 \u003c\u003d q \u003c\u003d 2*10^5), n表示有n个节点,q代表接下来有q次询问。\n第二行有n-1个整数,分别表示节点2到节点n的父亲节点序号。\n接下来q行,每行2个整数u,k(1 \u003c\u003d u, k\u003c\u003d n),表示询问从u节点开始,深度优先搜索k次以后是哪个节点"}},{"title":"Output","value":{"format":"HTML","content":"输出q行,对于每一行,输出一个整数,表示序号,如果序号不存在,输出-1."}},{"title":"Example","value":{"format":"HTML","content":"\u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e9 6\u003cbr\u003e1 1 1 3 5 3 5 7\u003cbr\u003e3 1\u003cbr\u003e1 5\u003cbr\u003e3 4\u003cbr\u003e7 3\u003cbr\u003e1 8\u003cbr\u003e1 9\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e3\u003cbr\u003e6\u003cbr\u003e8\u003cbr\u003e-1\u003cbr\u003e9\u003cbr\u003e4\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"","value":{"format":"HTML","content":"\u003ccenter\u003e \n \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/4c032195c19c77cbe8a2e19729e00cfa?v\u003d1629621005\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \n\u003c/center\u003e\n\u003cp\u003e样例如图所示\u003c/p\u003e"}}]}