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

29820번 - Love Letter 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2.5 초 1024 MB73464164.062%

문제

There are $n$ dragons numbered from 1ドル$ to $n$. Dragon $i$ has age $a_i$. The values of $a_i$ are distinct. Dragon 1ドル$ is Evirir the dragon.

Evirir has a letter it wants to send to dragon $t$. To avoid awkwardness caused by age difference, Evirir can send the letter to another dragon (not necessarily dragon $t$). The dragon who received the letter can then send the letter to another dragon, and so on. The goal is to eventually send the letter to dragon $t$.

For all $i$ (1ドル \le i \le n$), when dragon $i$ has the letter, it can send the letter to dragon $j$ in $|a_i - a_j|$ time$^1$. A dragon can "send" the letter to itself in 0ドル$ time. However, there are $k$ pairs of dragons who are close friends. If dragons $i$ and $j$ are close friends, then it takes 0ドル$ time instead for dragon $i$ to send a letter to dragon $j$ (and vice versa).

For each dragon $t$ (1ドル \le t \le n$), answer the question (independently): What is the minimum total time needed for dragon 1ドル$ to send a letter to dragon $t$?

$^1$Note: $|x|$ denotes the absolute value of $x$. For example, $|9| = 9,ドル $\lvert -6 \rvert = 6,ドル and $|0| = 0$. See \url{https://en.wikipedia.org/wiki/Absolute\_value} for more information.

입력

The first line contains two space-separated integers $n$ and $k$ (1ドル \le n\le 2 \cdot 10^5,ドル 0ドル \le k \le 2 \cdot 10^5$) -- the number of dragons and the number of pairs of close friends.

The second line contains $n$ distinct space-separated integers $a_1, a_2, \ldots, a_n$ (1ドル \le a_i \le 10^9$) -- the dragons' ages.

Then, $k$ lines follow. Each of the $k$ lines contains two space-separated integers $u$ and $v$ (1ドル \le u, v \le n,ドル $u \ne v$), which means that dragons $u$ and $v$ are close friends. It is guaranteed that the same pair of close friends will not appear twice (if $(u,v)$ appears, then $(u,v)$ and $(v,u)$ will not appear afterwards).

출력

Output $n$ space-separated integers $d_1, d_2, \ldots, d_n,ドル where $d_i$ is the minimum total time needed for dragon 1ドル$ to send the letter to dragon $i$.

제한

서브태스크

번호배점제한
118

$n, k \le 2000,ドル $a_i = i$

214

$n, k \le 2000$

39

$k = 0$

429

$a_i = i$ for all $i$ (1ドル \le i \le n$)

516

The sequence $a$ is non-decreasing, i.e. $a_i \le a_{i+1}$ for 1ドル \le i \le n-1$

614

No additional constraints

예제 입력 1

8 4
50 30 23 10 3 67 69 47
3 7
3 1
2 4
7 1

예제 출력 1

0 7 0 7 14 2 0 3

예제 입력 2

3 0
2 3 1

예제 출력 2

0 1 1

노트

Explanation for the first sample:

When $t = 1,ドル it takes 0ドル$ time because dragon 1ドル$ already has the letter.

When $t = 3,ドル since dragon 1ドル$ and 3ドル$ are close friends, dragon 1ドル$ can send the letter directly to dragon 3ドル$ in 0ドル$ time.

When $t = 2,ドル dragon 1ドル$ can send the letter to dragon 3ドル$ first in 0ドル$ time (they are close friends), then dragon 3ドル$ sends the letter to dragon 2ドル$ in $|23 - 30| = 7$ time. The total time taken is 0ドル + 7 = 7$.

When $t = 8,ドル dragon 1ドル$ can just send the letter directly to dragon 8ドル,ドル taking $|50 - 47| = 3$ time.

Here is one optimal way each for the remaining $t$'s ($i \xrightarrow{x} j$ means dragon $i$ sends the letter to dragon $j$ using $x$ time):

  • Dragon 4ドル$: 1ドル \xrightarrow{0} 3 \xrightarrow{7} 2 \xrightarrow{0} 4$
  • Dragon 5ドル$: 1ドル \xrightarrow{0} 3 \xrightarrow{7} 2 \xrightarrow{0} 4 \xrightarrow{7} 5$
  • Dragon 6ドル$: 1ドル \xrightarrow{0} 3 \xrightarrow{0} 7 \xrightarrow{2} 6$
  • Dragon 7ドル$: 1ドル \xrightarrow{0} 7$

출처

Olympiad > Malaysian Computing Olympiad > MCO 2023 B번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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