#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 intersections, numbered from to , and 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 for each intersection . 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 and , denoted as , is the minimum possible path risk among all paths connecting and . By definition, the only path from an intersection to itself is the trivial path containing only , so we have . Finally, she assigns a danger score to each intersection , denoted as:
In other words, the danger score of an intersection 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 () and (), indicating respectively the number of intersections and streets in Nogonia. Each intersection is identified by a distinct integer from to .
The second line contains integers ( for ), where is the danger rating of intersection .
Each of the next lines contains two integers and ( and ), indicating that there is a two-way street between intersections and .
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 integers , 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