{"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":"HTML","content":"\u003cstyle type\u003d\u0027text/css\u0027\u003e .input, .output {border: 1px solid #888888;} .output {margin-bottom:1em;position:relative;top:-1px;} .output pre,.input pre {background-color:#EFEFEF;line-height:1.25em;margin:0;padding:0.25em;} .title {background-color:#FFFFFF;border-bottom: 1px solid #888888;font-family:arial;font-weight:bold;padding:0.25em;} \u003c/style\u003e \u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027]], displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027]]}\n });\n \u003c/script\u003e\n \u003cscript type\u003d\"text/javascript\" async\n src\u003d\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\"\u003e\n \u003c/script\u003e\n\u003cp\u003eThe \u003ca href\u003d\"https://en.wikipedia.org/wiki/Breadth-first_search\"\u003eBFS\u003c/a\u003e algorithm is defined as follows : \u003c/p\u003e\n\u003col\u003e \n \u003cli\u003e Consider an undirected graph with vertices numbered from $$$1$$$ to $$$n$$$. Initialize $$$q$$$ as a new \u003ca href\u003d\"http://gg.gg/queue_en\"\u003equeue\u003c/a\u003e containing only vertex $$$1$$$, mark the vertex $$$1$$$ as used. \u003c/li\u003e\n \u003cli\u003e Extract a vertex $$$v$$$ from the head of the queue $$$q$$$. \u003c/li\u003e\n \u003cli\u003e Print the index of vertex $$$v$$$. \u003c/li\u003e\n \u003cli\u003e Iterate in arbitrary order through all such vertices $$$u$$$ that $$$u$$$ is a neighbor of $$$v$$$ and is not marked yet as used. Mark the vertex $$$u$$$ as used and insert it into the tail of the queue $$$q$$$. \u003c/li\u003e\n \u003cli\u003e If the queue is not empty, continue from step \u003cspan class\u003d\"tex-font-style-tt\"\u003e2\u003c/span\u003e. \u003c/li\u003e\n \u003cli\u003e Otherwise finish. \u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eSince the order of choosing neighbors of each vertex can vary, it turns out that there may be multiple sequences which \u003cspan class\u003d\"tex-font-style-tt\"\u003eBFS\u003c/span\u003e can print.\u003c/p\u003e\n\u003cp\u003eIn this problem you have to check whether a given sequence corresponds to some valid \u003cspan class\u003d\"tex-font-style-tt\"\u003eBFS\u003c/span\u003e traversal of the given tree \u003cspan class\u003d\"tex-font-style-bf\"\u003estarting from vertex $$$1$$$\u003c/span\u003e. The \u003ca href\u003d\"http://gg.gg/tree_en\"\u003etree\u003c/a\u003e is an undirected graph, such that there is exactly one simple path between any two vertices.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) which denotes the number of nodes in the tree. \u003c/p\u003e\n\u003cp\u003eThe following $$$n - 1$$$ lines describe the edges of the tree. Each of them contains two integers $$$x$$$ and $$$y$$$ ($$$1 \\le x, y \\le n$$$)\u0026nbsp;— the endpoints of the corresponding edge of the tree. It is guaranteed that the given graph is a tree.\u003c/p\u003e\n\u003cp\u003eThe last line contains $$$n$$$ distinct integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le n$$$)\u0026nbsp;— the sequence to check.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eYes\u003c/span\u003e\" (quotes for clarity) if the sequence corresponds to some valid \u003cspan class\u003d\"tex-font-style-tt\"\u003eBFS\u003c/span\u003e traversal of the given tree and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eNo\u003c/span\u003e\" (quotes for clarity) otherwise.\u003c/p\u003e\n\u003cp\u003eYou can print each letter in any case (upper or lower).\u003c/p\u003e"}},{"title":"Examples","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\u003e4\u003cbr\u003e1 2\u003cbr\u003e1 3\u003cbr\u003e2 4\u003cbr\u003e1 2 3 4\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\u003eYes\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e4\u003cbr\u003e1 2\u003cbr\u003e1 3\u003cbr\u003e2 4\u003cbr\u003e1 2 4 3\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\u003eNo\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eBoth sample tests have the same tree in them.\u003c/p\u003e\n\u003cp\u003eIn this tree, there are two valid \u003cspan class\u003d\"tex-font-style-tt\"\u003eBFS\u003c/span\u003e orderings: \u003c/p\u003e\n\u003cul\u003e \n \u003cli\u003e $$$1, 2, 3, 4$$$, \u003c/li\u003e\n \u003cli\u003e $$$1, 3, 2, 4$$$. \u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eThe ordering $$$1, 2, 4, 3$$$ doesn\u0027t correspond to any valid \u003cspan class\u003d\"tex-font-style-tt\"\u003eBFS\u003c/span\u003e order.\u003c/p\u003e"}}]}