{"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\u003cp\u003eYou are given a \u003cem\u003erooted tree\u003c/em\u003e\u0026nbsp;and an ordered list of queries. Each query is specified by two nodes \u003cem\u003eu \u003c/em\u003eand \u003cem\u003ev \u003c/em\u003eand the answer to a query is the lowest common ancestor of \u003cem\u003eu \u003c/em\u003eand \u003cem\u003ev\u003c/em\u003e.\u003c/p\u003e\r\n\u003cp\u003eRecall that the \u003cem\u003eLowest Common Ancestor\u003c/em\u003e\u0026nbsp;of two nodes is the node that is furthest from the root and also an ancestor of the two nodes. In this problem we use the convention that a node is in fact an ancestor of itself.\u003c/p\u003e\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eThe first line contains an integer \u003cstrong\u003eN, \u003c/strong\u003ethe number of nodes in the tree (\u003cstrong\u003eN \u0026lt;\u003d 10000\u003c/strong\u003e). Each of the next N lines will start with a number \u003cstrong\u003eM\u003c/strong\u003e the number of child nodes of the Nth node, (\u003cstrong\u003e0 \u0026lt;\u003d M \u0026lt;\u003d 999\u003c/strong\u003e) followed by M numbers the child nodes of the Nth node. Nodes will be labeled from 0 to N-1. Following will be a number \u003cstrong\u003eQ\u003c/strong\u003e, the number of queries that will be asked (\u003cstrong\u003eQ \u0026lt;\u003d 10000\u003c/strong\u003e). \u0026nbsp;Each of the next Q lines will have two numbers \u003cem\u003eu \u003c/em\u003eand \u003cem\u003ev\u003c/em\u003e\u0026nbsp;(\u003cstrong\u003e0 \u0026lt;\u003d u, v \u0026lt; N\u003c/strong\u003e) which specify the parameters of that specific query.\u003c/p\u003e\r\n\u003cp\u003eThe root of the tree will always be node 0.\u003c/p\u003e\r\n\u003cp\u003e\u003cspan style\u003d\"font-size: 1.17em;\"\u003e\u003cstrong\u003eOutput\u003c/strong\u003e\u003c/span\u003e\u003c/p\u003e\r\n\u003cp\u003eFor each query output the answer on its own line. Answers should follow the same order as given in the input.\u003c/p\u003e\r\n\u003ch3\u003eExample\u003c/h3\u003e\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\u003e3\n2 1 2\n0\n0\u0026nbsp;\n3\n1 2\n1 1\n2 2\u0026nbsp;\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n1\n2\u0026nbsp;\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e"}}]}