#abc362d. D - Shortest Path 3

D - Shortest Path 3

Score : 425425 points

问题陈述

给定一个简单的连通无向图,包含 NN 个顶点和 MM 条边。每个顶点 i(1iN)i\,(1\leq i \leq N) 有一个权重 AiA_i。每条边 j(1jM)j\,(1\leq j \leq M) 双向连接顶点 UjU_jVjV_j,并且有权重 BjB_j

在该图中,路径的权重定义为路径上出现的顶点和边的权重之和。

对于每个 i=2,3,,Ni=2,3,\dots,N,解决以下问题:

  • 找出从顶点 11 到顶点 ii 的路径的最小权重。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a simple connected undirected graph with NN vertices and MM edges. Each vertex i(1iN)i\,(1\leq i \leq N) has a weight AiA_i. Each edge j(1jM)j\,(1\leq j \leq M) connects vertices UjU_j and VjV_j bidirectionally and has a weight BjB_j.

The weight of a path in this graph is defined as the sum of the weights of the vertices and edges that appear on the path.

For each i=2,3,,Ni=2,3,\dots,N, solve the following problem:

  • Find the minimum weight of a path from vertex 11 to vertex ii.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • N1M2×105N-1 \leq M \leq 2 \times 10^5
  • 1Uj<VjN1 \leq U_j < V_j \leq N
  • (Ui,Vi)(Uj,Vj)(U_i, V_i) \neq (U_j, V_j) if iji \neq j.
  • The graph is connected.
  • 0Ai1090 \leq A_i \leq 10^9
  • 0Bj1090 \leq B_j \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \dots ANA_N

U1U_1 V1V_1 B1B_1

U2U_2 V2V_2 B2B_2

\vdots

UMU_M VMV_M BMB_M

Output

Print the answers for i=2,3,,Ni=2,3,\dots,N in a single line, separated by spaces.

Sample Input 1

3 3
1 2 3
1 2 1
1 3 6
2 3 2

Sample Output 1

4 9

Consider the paths from vertex 11 to vertex 22. The weight of the path 121 \to 2 is A1+B1+A2=1+1+2=4A_1 + B_1 + A_2 = 1 + 1 + 2 = 4, and the weight of the path 1321 \to 3 \to 2 is $A_1 + B_2 + A_3 + B_3 + A_2 = 1 + 6 + 3 + 2 + 2 = 14$. The minimum weight is 44.

Consider the paths from vertex 11 to vertex 33. The weight of the path 131 \to 3 is A1+B2+A3=1+6+3=10A_1 + B_2 + A_3 = 1 + 6 + 3 = 10, and the weight of the path 1231 \to 2 \to 3 is $A_1 + B_1 + A_2 + B_3 + A_3 = 1 + 1 + 2 + 2 + 3 = 9$. The minimum weight is 99.

Sample Input 2

2 1
0 1
1 2 3

Sample Output 2

4

Sample Input 3

5 8
928448202 994752369 906965437 942744902 907560126
2 5 975090662
1 2 908843627
1 5 969061140
3 4 964249326
2 3 957690728
2 4 942986477
4 5 948404113
1 3 988716403

Sample Output 3

2832044198 2824130042 4696218483 2805069468

Note that the answers may not fit in a 32-bit integer.