#P15098. [ICPC 2025 LAC] Dangerous City

[ICPC 2025 LAC] Dangerous City

题目描述

Alice is moving to the city of Nogonia, and to decide where to live, she is evaluating the safety of the city.

Nogonia is a planned city with NN intersections, numbered from 11 to NN, and MM streets. Each street connects two intersections bidirectionally. It is guaranteed that any intersection can reach all other intersections using the streets, and no two streets connect the same pair of intersections.

The government of Nogonia publishes a danger rating DiD_i for each intersection ii. However, Alice thinks these ratings are insufficient because she wants to assess the safety of moving through the city, not just where she lives. So, she developed her own way to measure how dangerous the city is.

For any given path in the city, Alice defines its path risk as the maximum danger rating among all intersections on that path, including its endpoints. The risk factor between two intersections UU and VV, denoted as f(U,V)f(U,V), is the minimum possible path risk among all paths connecting UU and VV. By definition, the only path from an intersection UU to itself is the trivial path containing only UU, so we have f(U,U)=DUf(U,U) = D_U. Finally, she assigns a danger score to each intersection UU, denoted as:

SU=V=1Nf(U,V)S_U = \sum_{V=1}^{N} f(U,V)

In other words, the danger score of an intersection UU is the sum of its risk factors to every intersection in the city.

Computing these danger scores for all intersections is not easy, so Alice asks for your help!

输入格式

The first line contains two integers NN (2N31052 \le N \le 3 \cdot 10^5) and MM (1M31051 \le M \le 3 \cdot 10^5), indicating respectively the number of intersections and streets in Nogonia. Each intersection is identified by a distinct integer from 11 to NN.

The second line contains NN integers D1,D2,,DND_1, D_2, \dots, D_N (1Di1091 \le D_i \le 10^9 for i=1,2,,Ni = 1, 2, \dots, N), where DiD_i is the danger rating of intersection ii.

Each of the next MM lines contains two integers UU and VV (1U,VN1 \le U, V \le N and UVU \ne V), indicating that there is a two-way street between intersections UU and VV.

It is guaranteed that there is at most one street between each pair of intersections and that any intersection can be reached from any other using one or more streets.

输出格式

Output a single line with NN integers S1,S2,,SNS_1, S_2, \dots, S_N, that is, the danger scores of all the intersections.

3 2
1 3 1
1 2
2 3
7 9 7
3 3
1 3 1
2 3
1 2
3 1
5 9 5