Problem D. Double Tree
时间限制 15000 ms
内存限制 512 MB
You are given two trees, both with $N$ vertices, numbered from 1 to $N$.
At the beginning, the weights of edges of both trees and the values of vertices of the first tree are given.
There are $Q$ operations. In each operation, the value of a vertice of the first tree will be modified. Please output $max_{1 \leq u < v \leq n}\left\{T_1.dis(u, v) + T_2.dis(u, v) + val(u) + val(v)\right\}$ after every operation.
Note that the symbol $T_{id}.dis(u,v)$ denotes the distance between vertice $u$ and vertice $v$ in the tree $id$.
Note that the distance between two vertices in some tree is defined as the sum of the weights in the simple path between the two vertices.
Note that the symbol $val(u)$ denotes the value of the vertice $u$ in the first tree.
输入数据
输出数据
For each test case, output $Q$ lines. Each line contains an integer denoting the answer.
样例输入
复制
5 3
1 2 3 4 5
1 2 1
1 3 2
1 4 3
1 5 4
1 2 1
1 3 2
1 4 3
1 5 4
1 100
1 1
2 100
样例输出
$ Mathjax font initiator $