{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n There is a tree having $n$ nodes, labeled from 1 to $n$. The root of the tree is always 1, and the depth of a node $p$ is the number of nodes on the shortest path between node $p$ and the root. \n \u003cbr\u003eIn computer science, the Lowest Common Ancestor (LCA) of two nodes $v$ and $w$ in a tree is the lowest (i.e. deepest) node that has both $v$ and $w$ as descendants, where we define each node to be a descendant of itself (so if $v$ has a direct connection from $w$, $w$ is the lowest common ancestor). \n \u003cbr\u003eYou have to answer $m$ queries. Each query gives two non-empty node sets $A$ and $B$, there might be some nodes in both sets. \n \u003cbr\u003eYou should select one node $x$ from set $A$, and one node $y$ from set $B$, $x$ and $y$ can be the same node. Your goal is to maximize the depth of the LCA of $x$ and $y$. \n \u003cbr\u003ePlease write a program to answer these queries. \n\u003c/div\u003e\n给定一棵以1为根的N个节点的树。 有M个询问,每个询问,给出两个点集,从两个集合中分别选出一个点,使得它们的LCA的深度最大。"}},{"title":"Input","value":{"format":"HTML","content":"The input contains several test cases, no more than 5 test cases. \n\u003cbr\u003eIn each test case, the first line contains two integers $n(1\\leq n\\leq 100000)$ and $m(1\\leq m\\leq 100000)$, denoting the number of nodes and queries. \n\u003cbr\u003eFor the next $n-1$ lines,each line contians two integers $a$ and $b$, denoting a bi-directional edge between node $a$ and $b$. \n\u003cbr\u003eThen there are $2m$ lines, every two lines describes one query. \n\u003cbr\u003eFor each query, the first line describes the set A. \n\u003cbr\u003eThe first integer $k(1\\leq k\\leq n)$ denotes the number of nodes in set $A$, and the next $k$ integers describing the nodes in set $A$. There might be some nodes appear multiple times in the set. \n\u003cbr\u003eThe second line describes the set $B$ in the same format of set $A$. \n\u003cbr\u003e \n\u003cbr\u003eIt is guaranteed that $\\sum k\\leq 100000$ in each test case. \n\u003cbr\u003e\n\u003cbr\u003e有多组测试数据\n\u003cbr\u003e每组测试数据第一行两个整数N和M,表示节点的数量和询问数。\n\u003cbr\u003e接下来N-1行,表示两个整数,表示树上的一条边。\n\u003cbr\u003e接下有M个询问,每个询问2行,每行表示一个点集,第一个数是集合的大小k,接下来有k个数。\n\u003cbr\u003e满足所有的k之和不超过100000\n\n\n\n"}},{"title":"Output","value":{"format":"HTML","content":"For every query, print a number denoting the answer, which means the maximum depth of the LCA.\n\u003cbr\u003e对于每个询问,在两个点集中,分别选出一个点并求LCA,输出所有情况中LCA的最大深度。"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e7 3\n1 2\n1 3\n3 4\n3 5\n4 6\n4 7\n1 6\n1 7\n2 6 7\n1 7\n2 5 4\n2 3 2\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e3\n4\n2\u003c/pre\u003e"}}]}