{"trustable":true,"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":"HTML","content":"\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eThis is a hard version of the problem. The only difference between an easy and a hard version is in the number of queries.\u003c/span\u003e\u003c/p\u003e\u003cp\u003ePolycarp grew a tree from $$$n$$$ vertices. We remind you that a tree of $$$n$$$ vertices is an undirected connected graph of $$$n$$$ vertices and $$$n-1$$$ edges that does not contain cycles.\u003c/p\u003e\u003cp\u003eHe calls a set of vertices \u003cspan class\u003d\"tex-font-style-it\"\u003epassable\u003c/span\u003e if there is such a path in the tree that passes through each vertex of this set without passing through any edge twice. The path can visit other vertices (not from this set).\u003c/p\u003e\u003cp\u003eIn other words, a set of vertices is called \u003cspan class\u003d\"tex-font-style-it\"\u003epassable\u003c/span\u003e if there is a simple path that passes through all the vertices of this set (and possibly some other).\u003c/p\u003e\u003cp\u003eFor example, for a tree below sets $$$\\{3, 2, 5\\}$$$, $$$\\{1, 5, 4\\}$$$, $$$\\{1, 4\\}$$$ are \u003cspan class\u003d\"tex-font-style-it\"\u003epassable\u003c/span\u003e, and $$$\\{1, 3, 5\\}$$$, $$$\\{1, 2, 3, 4, 5\\}$$$ are not.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/8fe0db1a43af85f8662ddde054102bce?v\u003d1716013502\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\" width\u003d\"189px\"\u003e \u003c/center\u003e\u003cp\u003ePolycarp asks you to answer $$$q$$$ queries. Each query is a set of vertices. For each query, you need to determine whether the corresponding set of vertices is \u003cspan class\u003d\"tex-font-style-bf\"\u003epassable\u003c/span\u003e.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of input contains a single integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) — number of vertices.\u003c/p\u003e\u003cp\u003eFollowing $$$n - 1$$$ lines a description of the tree..\u003c/p\u003e\u003cp\u003eEach line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \\le u, v \\le n$$$, $$$u \\ne v$$$) — indices of vertices connected by an edge.\u003c/p\u003e\u003cp\u003eFollowing line contains single integer $$$q$$$ ($$$1 \\le q \\le 10^5$$$)\u0026nbsp;— number of queries.\u003c/p\u003e\u003cp\u003eThe following $$$2 \\cdot q$$$ lines contain descriptions of sets.\u003c/p\u003e\u003cp\u003eThe first line of the description contains an integer $$$k$$$ ($$$1 \\le k \\le n$$$) — the size of the set.\u003c/p\u003e\u003cp\u003eThe second line of the description contains $$$k$$$ of distinct integers $$$p_1, p_2, \\dots, p_k$$$ ($$$1 \\le p_i \\le n$$$) — indices of the vertices of the set.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the sum of $$$k$$$ values for all queries does not exceed $$$2 \\cdot 10^5$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput $$$q$$$ lines, each of which contains the answer to the corresponding query. As an answer, output \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eYES\u003c/span\u003e\" if the set is \u003cspan class\u003d\"tex-font-style-bf\"\u003epassable\u003c/span\u003e, and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eNO\u003c/span\u003e\" otherwise.\u003c/p\u003e\u003cp\u003eYou can output the answer in any case (for example, the strings \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eyEs\u003c/span\u003e\", \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eyes\u003c/span\u003e\", \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eYes\u003c/span\u003e\" and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eYES\u003c/span\u003e\" will be recognized as a positive answer).\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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\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":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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\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"}}]}