You are given a tree consisting of n vertices. Let's denote the function LCM(x,y) Least Common Multiple of (x,y) Also let's denote dist(x,y) as the number of vertices on the simple path between vertices x and y In path x to y, Neighbor verticles (a,b) all LCM(a,b)<a*b Input n number of verticles The second line contains n integers a1, a2, ..., an (1≤ai≤2⋅105) — the numbers written on vertices. Then n−1 lines follow, each containing two integers x and y (1≤x,y≤n,x≠y) denoting an edge connecting vertex x with vertex y. It is guaranteed that these edges form a tree. Output Find two verticles (x,y) tha meets the conditions.








I whill write sloution tomorrow.
Auto comment: topic has been updated by coconutnutisagiantnut (previous revision, new revision, compare).
Could you elaborate more? You are defining dist(x, y) but it's never used, also I don't understand what conditions should be met. You don't clarify where a[i] are supposed to be used, and it's not verticles, it's vertices
You can find dist(x,y) using Bfs
No, I don't mean how to calculate, I mean where should I use that dist(x, y)?
You mast find verticles (x,y) dist(x,y) is maximum, and LCM(a[i],a[j]) where i,j are index of neighbor verticles must less then a[i]*a[j]
I wish you undarstand my task and can slove the problem.
LCM (a,b)<a*b
In LCM (a,b) i am mean LCM(a[i],a[j]) where i,j are index of neighbor verticles
Looks like a problem from some ongoing Indian contest...
I don't now about that i am from georgia