{"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\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"题目解释","value":{"format":"MD","content":"**这是这个问题的难版本。简单版本和难版本之间的唯一区别在于查询的数量。**\n\n波利卡普种了一个由 $$$n$$$ 个顶点组成的树。我们提醒你,一个由 $$$n$$$ 个顶点组成的树是一个无向连通图,它由 $$$n$$$ 个顶点和 $$$n-1$$$ 条边组成,且不包含任何循环。\n\n他称一组顶点为**可通行的**,如果在树中存在这样的路径,该路径通过这组顶点中的每一个顶点,而不需要通过任何边两次。路径可以访问其他(不在这组中的)顶点。\n\n换句话说,如果存在一条简单路径,该路径通过这组顶点中的所有顶点(可能还有其他顶点),那么这组顶点被称为**可通行的**。\n\n例如,对于下面的树,集合 $$$\\{3, 2, 5\\}$$$, $$$\\{1, 5, 4\\}$$$, $$$\\{1, 4\\}$$$ 是**可通行的**,而 $$$\\{1, 3, 5\\}$$$, $$$\\{1, 2, 3, 4, 5\\}$$$ 不是。\n\n![Tree Image](CDN_BASE_URL/8fe0db1a43af85f8662ddde054102bce?v\u003d1690686281)\n\n波利卡普要求你回答 $$$q$$$ 个查询。每个查询都是一组顶点。对于每个查询,你需要确定相应的顶点集合是否**可通行**。"}},{"title":"输入格式","value":{"format":"MD","content":"第一行输入包含一个单独的整数 $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) —— 顶点的数量。\n\n接下来的 $$$n - 1$$$ 行是树的描述。\n\n每行包含两个整数 $$$u$$$ 和 $$$v$$$ ($$$1 \\le u, v \\le n$$$, $$$u \\ne v$$$) —— 由边连接的顶点的索引。\n\n接下来的行包含一个单独的整数 $$$q$$$ ($$$1 \\le q \\le 10^5$$$) —— 查询的数量。\n\n接下来的 $$$2 \\cdot q$$$ 行包含集合的描述。\n\n描述的第一行包含一个整数 $$$k$$$ ($$$1 \\le k \\le n$$$) —— 集合的大小。\n\n描述的第二行包含 $$$k$$$ 个不同的整数 $$$p_1, p_2, \\dots, p_k$$$ ($$$1 \\le p_i \\le n$$$) —— 集合的顶点的索引。\n\n保证所有查询的 $$$k$$$ 值的总和不超过 $$$2 \\cdot 10^5$$$。"}},{"title":"输出格式","value":{"format":"MD","content":"输出 $$$q$$$ 行,每行包含对应查询的答案。如果集合是**可通行的**,则输出 \"YES\",否则输出 \"NO\"。\n\n你可以以任何大小写形式输出答案(例如,字符串 \"yEs\",\"yes\",\"Yes\" 和 \"YES\" 都会被识别为正面答案)。"}},{"title":"样例 #1","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003e输入\u003c/th\u003e\n \u003cth\u003e输出\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5\n1 2\n2 3\n2 4\n4 5\n5\n3\n3 2 5\n5\n1 2 3 4 5\n2\n1 4\n3\n1 3 5\n3\n1 5 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYES\nNO\nYES\nNO\nYES\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"样例 #2","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003e输入\u003c/th\u003e\n \u003cth\u003e输出\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5\n1 2\n3 2\n2 4\n5 2\n4\n2\n3 1\n3\n3 4 5\n3\n2 3 5\n1\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYES\nNO\nYES\nYES\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}