#B. 寄月饼moon

    Type: Default File IO: moon 1000ms 512MiB

寄月饼moon

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

信息组有 nn 个人,国庆节第 ii 个同学去到地点 aia_iaia_i 各不相同。老师编号为 11

正常情况下, ii 要给 jj 寄东西,需要花费时间 aiaj|a_i-a_j|

但是如果 iijj 之间建立了华附快线,那么寄东西的时间为 0。

东西可以从多个人之间传递。

刚过完中秋节,老师决定给每个同学发一个月饼。问老师给每个人发月饼的最短用时。

输入格式

第一行两个整数 nnkk,表示人数以及华附快线数量。

第二行 nn 个整数,a1ana_1 \dots a_n

接下来 kk 行,每行两个整数 uuvv,表示他们之间存在华附快线。

输出格式

输出 nn 个整数。

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

数据范围

对于所有数据 1n2105,0k21051\le n\le 2*10^5, 0\le k \le 2*10^5 1ai1091\le a_i\le 10^9

子任务1(18分): n,k2000,ai=in,k\le 2000, a_i=i

子任务2(14分): n,k2000n,k\le 2000

子任务3(9分):k=0k=0

子任务4(29分):ai=ia_i=i

子任务5(16分):aiai+1a_i\le a_{i+1}

子任务6(14分)

CSP-S模拟赛

Not Attended
Status
Done
Rule
OI
Problem
4
Start at
2023-10-17 8:00
End at
2023-10-17 12:00
Duration
4 hour(s)
Host
Partic.
25