Given a tree with N vertices. Each vertex has a value ai. For vertex i and j, if some vextex x is on the path between i and j, and x is neither i nor j, we update Ansx=max(Ansx,GCD(ai,aj)). GCD means the greatest common divisor function. Ans is an array of N zeros initial.
Find the Ans array after all updation.
First line contains an integer N(1≤N≤105).
Second line contains N integers, represent the array a(1≤ai≤105).
Each of the next N−1 lines contains two integers u,v, represent an edge in the tree.
N integers in one line, represent the array Ans, separated by space.
Vertex 2 is updated by 1 and 5,
Vertex 3,6 is updated by 5 and 7,
Vertex 4 is updated by 3 and 5,