CF1783G.Weighed Tree Radius
省选/NOI-
通过率:0%
时间限制:6.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree of n vertices and n−1 edges. The i-th vertex has an initial weight ai.
Let the distance dv(u) from vertex v to vertex u be the number of edges on the path from v to u. Note that dv(u)=du(v) and dv(v)=0.
Let the weighted distance wv(u) from v to u be wv(u)=dv(u)+au. Note that wv(v)=av and wv(u)=wu(v) if au=av.
Analogically to usual distance, let's define the eccentricity e(v) of vertex v as the greatest weighted distance from v to any other vertex (including v itself), or e(v)=1≤u≤nmaxwv(u).
Finally, let's define the radius r of the tree as the minimum eccentricity of any vertex, or r=1≤v≤nmine(v).
You need to perform m queries of the following form:
- vj xj — assign avj=xj.
After performing each query, print the radius r of the current tree.
给你一棵包含 n 个顶点和 n−1 条边的树。第 i 个顶点的初始权重为 ai。
定义顶点 v 到顶点 u 的距离 dv(u) 为从 v 到 u 的路径上的边数。注意:dv(u)=du(v),且 dv(v)=0。
定义顶点 v 到顶点 u 的加权距离 wv(u) 为 wv(u)=dv(u)+au。注意:wv(v)=av,且当 au=av 时,有 wv(u)=wu(v)。
类比于通常的距离概念,定义顶点 v 的离心率 e(v) 为 v 到任意其他顶点(包括 v 自身)的最大加权距离,即 e(v)=1≤u≤nmaxwv(u)。
最后,定义该树的半径 r 为所有顶点离心率的最小值,即 r=1≤v≤nmine(v)。
你需要执行 m 次如下形式的查询:
- vj xj — 将 avj 赋值为 xj。
每次查询执行完毕后,请输出当前树的半径 r。
输入格式
The first line contains the single integer n (2≤n≤2⋅105) — the number of vertices in the tree.
The second line contains n integers a1,…,an (0≤ai≤106) — the initial weights of vertices.
Next n−1 lines contain edges of tree. The i-th line contains two integers ui and vi (1≤ui,vi≤n; ui=vi) — the corresponding edge. The given edges form a tree.
The next line contains the single integer m (1≤m≤105) — the number of queries.
Next m lines contain queries — one query per line. The j-th query contains two integers vj and xj (1≤vj≤n; 0≤xj≤106) — a vertex and it's new weight.
第一行包含一个整数 n(2≤n≤2⋅105)——树中顶点的数量。
第二行包含 n 个整数 a1,…,an(0≤ai≤106)——各顶点的初始权值。
接下来的 n−1 行描述树的边。第 i 行包含两个整数 ui 和 vi(1≤ui,vi≤n;ui=vi)——对应的一条边。所给边构成一棵树。
下一行包含一个整数 m(1≤m≤105)——查询的数量。
接下来的 m 行每行描述一个查询。第 j 个查询包含两个整数 vj 和 xj(1≤vj≤n;0≤xj≤106)——一个顶点及其新的权值。
输出格式
Print m integers — the radius r of the tree after performing each query.
输出 m 个整数——每次查询操作后树的半径 r。
输入输出样例
输入#1
6 1 3 3 7 0 1 2 1 1 3 1 4 5 4 4 6 5 4 7 4 0 2 5 5 10 5 5
输出#1
7 4 5 10 7
说明/提示
After the first query, you have the following tree:

The marked vertex in the picture is the vertex with minimum e(v), or r=e(4)=7. The eccentricities of the other vertices are the following: e(1)=8, e(2)=9, e(3)=9, e(5)=8, e(6)=8.
The tree after the second query:

The radius r=e(1)=4.
After the third query, the radius r=e(2)=5:

第一次查询后,你得到如下树:

图中标记的顶点是使 e(v) 取得最小值的顶点,即 r=e(4)=7。其余各顶点的离心率如下:e(1)=8,e(2)=9,e(3)=9,e(5)=8,e(6)=8。
第二次查询后的树:

此时半径为 r=e(1)=4。
第三次查询后,半径为 r=e(2)=5:

输入解题思路,AI测评打分。不知道怎么写?