2622.Happy Tree Party

Time Limit: 1s Memory Limit: 256MB

Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. In case you forget, a tree is a connected non-directed graph without cycles. After the present was granted, m guests consecutively come to Bogdan's party. When the i-th guest comes, he performs exactly one of the two possible operations: Chooses some number yi, and two vertecies ai and bi. After that, he moves along the edges of the tree from vertex ai to vertex bi using the shortest path (of course, such a path is unique in the tree). Every time he moves along some edge j, he replaces his current number yi by 2622_1.png, that is, by the result of integer division yi div xj. Chooses some edge pi and replaces the value written in it xpi by some positive integer ci \lt xpi. As Bogdan cares about his guests, he decided to ease the process. Write a program that performs all the operations requested by guests and outputs the resulting value yi for each i of the first type.

Input Format(From the terminal/stdin)

Input The first line of the input contains integers, n and m (2 \le n \le 200000, 1 \le m \le 200000)- the number of vertecies in the tree granted to Bogdan by his mom and the number of guests that came to the party respectively.Next n-1 lines contain the description of the edges. The i-th of these lines contains three integers ui, vi and xi (1 \le ui,vi \le n, ui \neq vi, 1 \le xi \le 1018), denoting an edge that connects vertecies ui and vi, with the number xi initially written on it.The following m lines describe operations, requested by Bogdan's guests. Each description contains three or four integers and has one of the two possible forms: 1 ai bi yi corresponds to a guest, who chooses the operation of the first type. 2 pi ci corresponds to a guests, who chooses the operation of the second type. It is guaranteed that all the queries are correct, namely 1 \le ai,bi \le n, 1 \le pi \le n-1, 1 \le yi \le 1018 and 1 \le ci \lt xpi, where xpi represents a number written on edge pi at this particular moment of time that is not necessarily equal to the initial value xpi, as some decreases may have already been applied to it. The edges are numbered from 1 to n-1 in the order they appear in the input.

Output Format(To the terminal/stdout)

Output For each guest who chooses the operation of the first type, print the result of processing the value yi through the path from ai to bi.

Sample Input 1

Copy
6 6
1 2 1
1 3 7
1 4 4
2 5 5
2 6 2
1 4 6 17
2 3 2
1 4 6 17
1 5 5 20
2 4 1
1 5 1 3
 · \n
 · · \n
 · · \n
 · · \n
 · · \n
 · · \n
 · · ·  \n
 · · \n
 · · ·  \n
 · · ·  \n
 · · \n
 · · · \n

Sample Output 1

Copy
2
4
20
3
 \n
 \n
  \n
 \n

Sample Input 2

Copy
5 4
1 2 7
1 3 3
3 4 2
3 5 5
1 4 2 100
1 5 4 1
2 2 2
1 1 3 4
 · \n
 · · \n
 · · \n
 · · \n
 · · \n
 · · ·   \n
 · · · \n
 · · \n
 · · · \n

Sample Output 2

Copy
2
0
2
 \n
 \n
 \n

Hints

Initially the tree looks like this: 2622_2.png The response to the first query is: 2622_3.png = 2After the third edge is changed, the tree looks like this: 2622_4.png The response to the second query is: 2622_5.png = 4In the third query the initial and final vertex coincide, that is, the answer will be the initial number 20.After the change in the fourth edge the tree looks like this: 2622_6.png In the last query the answer will be: 2622_7.png = 3

Submit

请先 登录

© 2025 FAQs