Stevie : "The more you play with Christmas Trees, the more addicted you are to them. Let's go on". Legends serve a club selflessly for ages without any noise off the pitch. Do you remember the headed goal vs the Gunners with a highly bandaged head by this guy : ?
You are given a Tree T consisting of N nodes where node i of the tree has number \(A[i]\) written on it. Now, you need to process 2 kinds of queries on this tree.
\( 1 \space X \space Y \) : Update the number written on node with index X to Y
\( 2 \space U \space V \space K \) : Find if the product of number written on each nodes lying on the path from node U to V is divisible by the number K.
The answer to the second kind of query is either a YES or NO .
Can you answer all the given queries efficiently?
Input Format :
The first line contains 2 space separated integer N and Q denoting the number of nodes in tree T and the number of queries respectively.
The next line contains N space separated integers, where the \(i^{th}\) integer denotes the number initially written on node i i.e. \(A[i]\)
Each of the next \( N-1 \) lines contains 2 space separated integers U and V denoting an undirected edge between nodes with index U and V in tree T.
It is guaranteed that the input edges are such that it always forms a valid tree.
Each of the next Q lines contains a query of either of the two types on a single line.
\(1^{st}\) type : \( 1 \space X \space Y \)
\( 2^{nd}\) type : \( 2 \space U \space V \space K \)
Output Format:
Print the answer to each query of type 2 in the order they appear in the input on a new line. The answer to the queries shall be either a YES or a NO.
Constraints :
\( 1 \le N,Q \le 100,000 \)
\( 2 \le A[i],Y ,K \le 200,000 \)
\( 1 \le U,V,X \le N \)
Query 1: The path from 1 to 5 is 1->2->3->4->5. The product of numbers written on these nodes is 12345 which is divisible by 120.
Query 2: The path from 1 to 2 is 1->2. The product of numbers written on these nodes is 2*2 which is divisible by 4.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor