Dangerous City
시간 제한1초메모리 제한2048 MB
모든 정점 U에 대해, U에서 다른 모든 정점으로 가는 경로마다 경로 위 위험 등급의 최댓값을 구하고 그 최솟값들을 모두 더해 N개의 합을 출력한다.
문제
Alice is moving to the city of Nlogonia, and to decide where to live, she is evaluating the safety of the city.
Nlogonia 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 Nlogonia 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 Nlogonia. 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.