Codeforces Round 329 (Div. 2)
D
Happy Tree Party
Codeforces
2400
原题
← CE →
翻译中…

Bogdan has a birthday today and mom gave him a tree consisting of $*n*$ vertecies. For every edge of the tree $*i*$, some number $*x*_{*i*}$ 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:

翻译中…
  1. Chooses some number $*y*_{*i*}$, and two vertecies $*a*_{*i*}$ and $*b*_{*i*}$. After that, he moves along the edges of the tree from vertex $*a*_{*i*}$ to vertex $*b*_{*i*}$ 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 $*y*_{*i*}$ by image, that is, by the result of integer division $*y*_{*i*}$ div $*x*_{*j*}$.
  2. Chooses some edge $*p*_{*i*}$ and replaces the value written in it $*x*_{*p*_{*i*}}$ by some positive integer $*c*_{*i*} < *x*_{*p*_{*i*}}$.
翻译中…

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 $*y*_{*i*}$ for each $*i*$ of the first type.

翻译中…

Input

翻译中…

The first line of the input contains integers, $*n*$ and $*m*$ ($2 ≤ *n* ≤ 200 000$, $1 ≤ *m* ≤ 200 000$) — 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 $*u*_{*i*}$, $*v*_{*i*}$ and $*x*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$, $*u*_{*i*} ≠ *v*_{*i*}$, $1 ≤ *x*_{*i*} ≤ 10^{18}$), denoting an edge that connects vertecies $*u*_{*i*}$ and $*v*_{*i*}$, with the number $*x*_{*i*}$ 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$ $*a*_{*i*}$ $*b*_{*i*}$ $*y*_{*i*}$ corresponds to a guest, who chooses the operation of the first type.
  • $2$ $*p*_{*i*}$ $*c*_{*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 ≤ n

翻译中…

,

翻译中…

1 ≤ pi ≤ n - 1

翻译中…

,

翻译中…

1 ≤ yi ≤ 1018

翻译中…

and

翻译中…

1 ≤ ci < 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

翻译中…

For each guest who chooses the operation of the first type, print the result of processing the value $*y*_{*i*}$ through the path from $*a*_{*i*}$ to $*b*_{*i*}$.

翻译中…

Note

翻译中…

Initially the tree looks like this: image The response to the first query is: image = 2After the third edge is changed, the tree looks like this: image The response to the second query is: image = 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: image In the last query the answer will be: image = 3

翻译中…

样例

Input #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
Output #1
2
4
20
3
InputCopy OutputCopy
Input #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
Output #2
2
0
2
InputCopy OutputCopy
题目信息
题号
593D
时间限制
3 s
内存限制
256 MB
标签
数据结构
DFS 及类似
图论
数学
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。