{"trustable":true,"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":"\u003cdiv class\u003d\"panel_content\"\u003e二叉树是一个有限的顶点集,可以是空集,也可以由根节点 r 和两个不相交的称为左子树和右子树的二叉树组成。二叉树的顶点可以按照三种最重要的方式进行系统遍历或排序,它们分别是前序遍历、中序遍历和后序遍历。设 T 是一个具有根节点 r 和子树 T1、T2 的二叉树。\u003cbr\u003e\u003cbr\u003e在对 T 的顶点进行前序遍历时,我们首先访问根节点 r,然后按前序遍历访问 T1 的顶点,最后按前序遍历访问 T2 的顶点。\u003cbr\u003e\u003cbr\u003e在对 T 的顶点进行中序遍历时,我们按中序遍历访问 T1 的顶点,然后访问根节点 r,最后按中序遍历访问 T2 的顶点。\u003cbr\u003e\u003cbr\u003e在对 T 的顶点进行后序遍历时,我们按后序遍历访问 T1 的顶点,然后按后序遍历访问 T2 的顶点,最后访问根节点 r。\u003cbr\u003e\u003cbr\u003e现在给定某个二叉树的前序遍历序列和中序遍历序列,请尝试找出其后序遍历序列。\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/43f5e5ba858435faa9d9798d5af4fcac?v\u003d1708168781\"\u003e\u003c/center\u003e\u003c/div\u003e"}},{"title":"输入","value":{"format":"HTML","content":"每个测试用例包含多个测试案例。每个测试案例的第一行包含一个整数 n (1\u0026lt;\u003dn\u0026lt;\u003d1000),表示二叉树的顶点数。接下来两行分别表示前序遍历序列和中序遍历序列。你可以假设它们总是对应于一个唯一的二叉树。\u003cbr\u003e"}},{"title":"输出","value":{"format":"HTML","content":"对于每个测试案例,输出一行指定相应的后序遍历序列。\u003cbr\u003e"}},{"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\u003e9\r\n1 2 4 7 3 5 8 9 6\r\n4 7 2 1 8 5 9 3 6\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e7 4 2 8 9 5 6 3 1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}}]}