Logo
(追記) (追記ここまで)

34735번 - Dangerous City 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB21151266.667%

문제

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 $N$ intersections, numbered from 1ドル$ to $N,ドル and $M$ 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 $D_i$ for each intersection $i$. 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 $U$ and $V,ドル denoted as $f(U, V ),ドル is the minimum possible path risk among all paths connecting $U$ and $V$. By definition, the only path from an intersection $U$ to itself is the trivial path containing only $U,ドル so we have $f(U, U) = D_U$. Finally, she assigns a danger score to each intersection $U,ドル denoted as:

$$S_U = \displaystyle\sum_{V=1}^{N}{f(U,V)}$$

In other words, the danger score of an intersection $U$ 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 $N$ (2ドル ≤ N ≤ 3 \cdot 10^5$) and $M$ (1ドル ≤ M ≤ 3 \cdot 10^5$), indicating respectively the number of intersections and streets in Nlogonia. Each intersection is identified by a distinct integer from 1ドル$ to $N$.

The second line contains $N$ integers $D_1, D_2, \dots , D_N$ (1ドル ≤ D_i ≤ 10^9$ for $i = 1, 2, \dots , N$), where $D_i$ is the danger rating of intersection $i$.

Each of the next $M$ lines contains two integers $U$ and $V$ (1ドル ≤ U, V ≤ N$ and $U \ne V$), indicating that there is a two-way street between intersections $U$ and $V$.

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 $N$ integers $S_1, S_2, \dots , S_N,ドル that is, the danger scores of all the intersections.

제한

예제 입력 1

3 2
1 3 1
1 2
2 3

예제 출력 1

7 9 7

예제 입력 2

3 3
1 3 1
2 3
1 2
3 1

예제 출력 2

5 9 5

노트

출처

ICPC > Regionals > Latin America > Latin America Championship > The 2025 ICPC Latin America Championship D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /