{"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":"\u003cdiv class\u003d\"panel_content\"\u003e\n Recently, TeaTree acquire new knoledge gcd (Greatest Common Divisor), now she want to test you.\n \u003cbr\u003eAs we know, TeaTree is a tree and her root is node 1, she have n nodes and n-1 edge, for each node i, it has it’s value v[i].\n \u003cbr\u003eFor every two nodes i and j (i is not equal to j), they will tell their Lowest Common Ancestors (LCA) a number : gcd(v[i],v[j]).\n \u003cbr\u003eFor each node, you have to calculate the max number that it heard. some definition:\n \u003cbr\u003eIn graph theory and computer science, the lowest common ancestor (LCA) of two nodes u and v in a tree is the lowest (deepest) node that has both u and v as descendants, where we define each node to be a descendant of itself.\n\u003c/div\u003e\n\n给一颗 $n$ 个节点的树,每个节点有个权值 $a_i$,求出对于每个 $k$ ,求 $\\max \\{\\gcd(a_i,a_j) \\}(\\mathrm{sat.} \\ \\ lca(i,j)\u003dk)$\n"}},{"title":"Input","value":{"format":"HTML","content":"On the first line, there is a positive integer n, which describe the number of nodes.\n\u003cbr\u003eNext line there are n-1 positive integers f[2] ,f[3], …, f[n], f[i] describe the father of node i on tree.\n\u003cbr\u003eNext line there are n positive integers v[2] ,v[3], …, v[n], v[i] describe the value of node i.\n\u003cbr\u003en\u0026lt;\u003d100000, f[i]\u0026lt;i, v[i]\u0026lt;\u003d100000"}},{"title":"Output","value":{"format":"HTML","content":"Your output should include n lines, for i-th line, output the max number that node i heard.\n\u003cbr\u003eFor the nodes who heard nothing, output -1."}},{"title":"Sample","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\u003e\u003cpre\u003e4\n1 1 3\n4 1 6 9\n\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\u003cpre\u003e2\n-1\n3\n-1\n\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}