Codeforces Round 430 (Div. 2)
C
Ilya And The Tree
Codeforces
2000
原题
← BD →
翻译中…

Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex $1$. There is an integer number written on each vertex of the tree; the number written on vertex $*i*$ is equal to $*a*_{*i*}$.

翻译中…

Ilya believes that the beauty of the vertex $*x*$ is the greatest common divisor of all numbers written on the vertices on the path from the root to $*x*$, including this vertex itself. In addition, Ilya can change the number in one arbitrary vertex to $0$ or leave all vertices unchanged. Now for each vertex Ilya wants to know the maximum possible beauty it can have.

翻译中…

For each vertex the answer must be considered independently.

翻译中…

The beauty of the root equals to number written on it.

翻译中…

Input

翻译中…

First line contains one integer number $*n*$ — the number of vertices in tree ($1 ≤ *n* ≤ 2·10^{5}$).

翻译中…

Next line contains $*n*$ integer numbers $*a*_{*i*}$ ($1 ≤ *i* ≤ *n*$, $1 ≤ *a*_{*i*} ≤ 2·10^{5}$).

翻译中…

Each of next $*n* - 1$ lines contains two integer numbers $*x*$ and $*y*$ ($1 ≤ *x*, *y* ≤ *n*$, $*x* ≠ *y*$), which means that there is an edge $(*x*, *y*)$ in the tree.

翻译中…

Output

翻译中…

Output $*n*$ numbers separated by spaces, where $*i*$-th number equals to maximum possible beauty of vertex $*i*$.

翻译中…

样例

Input #1
2
6 2
1 2
Output #1
6 6
InputCopy OutputCopy
Input #2
3
6 2 3
1 2
1 3
Output #2
6 6 6
InputCopy OutputCopy
Input #3
1
10
Output #3
10
InputCopy OutputCopy
题目信息
题号
842C
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
图论
数学
数论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。