CF593D.Happy Tree Party

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bogdan has a birthday today and mom gave him a tree consisting of nn vertecies. For every edge of the tree ii , some number xix_{i} was written on it. In case you forget, a tree is a connected non-directed graph without cycles. After the present was granted, mm guests consecutively come to Bogdan's party. When the ii -th guest comes, he performs exactly one of the two possible operations:

  1. Chooses some number yiy_{i} , and two vertecies aia_{i} and bib_{i} . After that, he moves along the edges of the tree from vertex aia_{i} to vertex bib_{i} using the shortest path (of course, such a path is unique in the tree). Every time he moves along some edge jj , he replaces his current number yiy_{i} by , that is, by the result of integer division yiy_{i} div xjx_{j} .
  2. Chooses some edge pip_{i} and replaces the value written in it xpix_{pi} by some positive integer c_{i}<x_{pi} .

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 yiy_{i} for each ii of the first type.

输入格式

The first line of the input contains integers, nn and mm ( 2<=n<=2000002<=n<=200000 , 1<=m<=2000001<=m<=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 n1n-1 lines contain the description of the edges. The ii -th of these lines contains three integers uiu_{i} , viv_{i} and xix_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n , uiviu_{i}≠v_{i} , 1<=xi<=10181<=x_{i}<=10^{18} ), denoting an edge that connects vertecies uiu_{i} and viv_{i} , with the number xix_{i} initially written on it.

The following mm lines describe operations, requested by Bogdan's guests. Each description contains three or four integers and has one of the two possible forms:

  • 11 aia_{i} bib_{i} yiy_{i} corresponds to a guest, who chooses the operation of the first type.
  • 22 pip_{i} cic_{i} corresponds to a guests, who chooses the operation of the second type.

It is guaranteed that all the queries are correct, namely 1<=ai,bi<=n1<=a_{i},b_{i}<=n , 1<=pi<=n11<=p_{i}<=n-1 , 1<=yi<=10181<=y_{i}<=10^{18} and 1<=c_{i}<x_{pi} , where xpix_{pi} represents a number written on edge pip_{i} at this particular moment of time that is not necessarily equal to the initial value xpix_{pi} , as some decreases may have already been applied to it. The edges are numbered from 11 to n1n-1 in the order they appear in the input.

输出格式

For each guest who chooses the operation of the first type, print the result of processing the value yiy_{i} through the path from aia_{i} to bib_{i} .

输入输出样例

  • 输入#1

    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
    

    输出#1

    2
    4
    20
    3
    
  • 输入#2

    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
    

    输出#2

    2
    0
    2
    

说明/提示

Initially the tree looks like this:

The response to the first query is: = 2

After the third edge is changed, the tree looks like this:

The response to the second query is: = 4

In 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:

In the last query the answer will be: = 3

首页