#P4338. [ZJOI2018] 历史

    ID: 3268 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2018各省省选浙江树链剖分,树剖Link-Cut Tree,LCT构造

[ZJOI2018] 历史

Description

There are nn cities in this world, connected by exactly n1n - 1 bidirectional roads, so any two cities are mutually reachable. City 11 lies at the center of the world; whoever takes this city dominates the world.

Initially, none of the nn cities is controlled by any country. As society develops, some cities will rise to form countries and seize world hegemony. For convenience, we label the country that rises at city ii as country ii. During the rise at city ii, country ii will take control of all cities on the path from city ii to city 11.

The rise of a new city often means war and death. If, during the rise of country ii, it needs to take a city that is currently controlled by another country jj (jij \ne i), then country ii must declare war on country jj and fight.

Now, Kelian knows that in history, city ii rose exactly aia_i times. However, the relative order of these events is unknown. The only information is that while one city is rising to dominate the world, no new city will start rising.

War is catastrophic for the people. Kelian defines the disaster degree of a single rise as the number of distinct countries it goes to war with during that rise (multiple wars against the same country within one rise count only once). She wants to know, among all possible rise orders, what is the maximum possible sum of the disaster degrees.

Meanwhile, thanks to archaeologists’ efforts, more and more historical records are being unearthed. Based on these new materials, Kelian will adjust the values of aia_i. Specifically, she will perform operations on aia_i, each time adding ww to axa_x. She hopes that after each modification, the maximum total disaster degree can be computed.

However, Kelian is not interested in complicated calculations, so she wants you to help her compute these values.

Additional notes:

  • Multiple rises at the same city form the same country. This means that if the same city rises twice in a row, it will not go to war with any country, because those cities are already under its control.
  • Over the course of history, country ii may temporarily control no city. This does not mean country ii is destroyed. When city ii rises, country ii will still take control of all cities on the path from 11 to ii.

Input Format

The first line contains two integers nn, mm, the number of cities and the number of operations.

The second line contains nn integers, the initial values of aia_i.

The next n1n - 1 lines each contain two integers uiu_i, viv_i (1ui,vin1 \le u_i, v_i \le n) describing a road.

The next mm lines each contain two integers xix_i, wiw_i, meaning add wiw_i to axia_{x_i}.

Output Format

Output m+1m + 1 lines. The first line is the answer for the initial aia_i. Each of the next mm lines is the answer after that modification.

5 3 
1 1 1 1 1 
1 2 
1 3 
2 4 
2 5 
2 1 
3 1
4 1
6 
7 
9
10

Hint

Before the modifications, if the cities rise in the order 4,1,5,3,24, 1, 5, 3, 2, then they will go to war with 0,1,2,1,20, 1, 2, 1, 2 countries, respectively.

A total of 66 pairs of hostile relationships will be produced. It can be proven that this is the maximum among all rise orders.

Translated by ChatGPT 5