#P4069. [SDOI2016] 游戏

    ID: 2976 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016线段树各省省选山东最近公共祖先,LCA树链剖分,树剖

[SDOI2016] 游戏

Description

Alice and Bob are playing a game.

The game is played on a tree with nn vertices. Initially, each vertex contains exactly one number, which is 123456789123456789123456789123456789.

Sometimes, Alice chooses the path from ss to tt and adds a number to every vertex on this path. For a vertex rr on the path, if the distance between rr and ss is disdis, then the number Alice adds to rr is a×dis+ba \times dis + b.

Sometimes, Bob chooses the path from ss to tt. He must first choose a vertex on this path, and then choose one number stored at that vertex.

Bob wants the chosen number to be as small as possible, but the large amount of numbers makes him dazzled. He needs your help to find the smallest number he can choose.

Input Format

The first line contains two integers n,mn, m, the number of vertices of the tree and the number of operations.

The next n1n - 1 lines each contain three integers u,v,wu, v, w, indicating there is an edge connecting uu and vv with length ww.

The next mm lines each begin with an integer 11 or 22.

If the first integer is 11, it denotes Alice’s operation, followed by four integers s,t,a,bs, t, a, b.

If the first integer is 22, it denotes Bob’s operation, followed by two integers s,ts, t.

Output Format

Each time Bob performs an operation, output one line with a single integer, representing the smallest number he can choose.

3 5
1 2 10
2 3 20
2 1 3
1 2 3 5 6
2 2 3
1 2 3 -5 -6
2 2 3
123456789123456789
6
-106

Hint

Test points 1–2: n10n \leq 10, m10m \leq 10, a10000|a| \leq 10000.

Test points 3–4: n1000n \leq 1000, m1000m \leq 1000, a10000|a| \leq 10000.

Test point 5: n100000n \leq 100000, m100000m \leq 100000, a=0a = 0, the tree is a path.

Test points 6–7: n100000n \leq 100000, m100000m \leq 100000, a=0a = 0.

Test point 8: n100000n \leq 100000, m100000m \leq 100000, a=1a = 1, the tree is a path.

Test points 9–10: n100000n \leq 100000, m100000m \leq 100000, a=1a = 1.

Test points 11–13: n100000n \leq 100000, m100000m \leq 100000, a10000|a| \leq 10000, the tree is a path.

Test points 14–20: n100000n \leq 100000, m100000m \leq 100000, a10000|a| \leq 10000.

For all testdata, 0w,b1090 \le w, |b| \le 10^9.

Translated by ChatGPT 5