#P4315. 月下“毛景树”

    ID: 3075 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树最近公共祖先,LCA树链剖分,树剖

月下“毛景树”

Description

Crawl, crawl~ crawl, crawl~~ The caterpillar crawled under a small "Maojing Tree" and found that it bore its favorite maomao fruits. The "Maojing Tree" has NN nodes and N1N-1 edges. There are no maomao fruits on the nodes; all maomao fruits grow on the edges. This "Maojing Tree" has magical power: it can change the number of maomao fruits on its edges:

  • Change k w: Set the number of maomao fruits on the kk-th edge to ww.
  • Cover u v w: Set the number of maomao fruits on every edge along the path between nodes uu and vv to ww.
  • Add u v w: Increase by ww the number of maomao fruits on every edge along the path between nodes uu and vv.

Since the caterpillar is greedy, it will ask the following query:

  • Max u v: Query the maximum number of maomao fruits among all edges along the path between nodes uu and vv.

Input Format

The first line contains a positive integer NN.

The next N1N-1 lines each contain three positive integers UiU_i, ViV_i, and WiW_i. The (i+1)(i+1)-th line describes the ii-th edge: it connects nodes UiU_i and ViV_i, and there are WiW_i maomao fruits on that edge.

Then follow the operations and queries, one per line, terminated by a single line Stop.

Output Format

For each Max query, output its answer on a separate line.

4
1 2 8
1 3 7
3 4 9
Max 2 4
Cover 2 4 5
Add 1 4 10
Change 1 16
Max 2 4
Stop
9
16

Hint

For all testdata, 1N1051 \le N \le 10^5, and the total number of operations and queries does not exceed 10510^5.

It is guaranteed that at any time, the number of maomao fruits on every edge does not exceed 10910^9.

Translated by ChatGPT 5