#abc307f. F - Virus 2

F - Virus 2

Score : 550550 points

问题描述

NN 个房间,编号为 11, 22, \ldots, NN,每个房间内住着一个人,并且有 MM 条走廊连接两个不同的房间。第 ii 条走廊连接了房间 UiU_i 和房间 ViV_i,其长度为 WiW_i

有一天(我们称这一天为第 00 天),住在房间 A1,A2,,AKA_1, A_2, \ldots, A_KKK 个人(新)感染了一种病毒。接下来的 DD 天中,在第 ii 天(1iD1\leq i\leq D),感染以以下方式扩散:

在第 (i1)(i-1) 天夜晚结束时已感染的人,在第 ii 天夜晚结束时仍然保持感染状态。

对于未感染者,如果他们在第 (i1)(i-1) 天夜晚结束时所居住的房间与至少一个感染者的房间之间的距离小于等于 XiX_i,则他们将被新感染。这里,房间 PPQQ 之间的距离定义为仅使用走廊从房间 PP 移动到房间 QQ 时,所有可能走廊长度之和的最小值。若无法仅通过走廊从房间 PP 移动到房间 QQ,则设定该距离为 1010010^{100}

对于每个 ii1iN1\leq i\leq N),请输出住在房间 ii 的人在哪一天被新感染。如果在第 DD 天夜晚结束时他们仍未被感染,则输出 1-1

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN rooms numbered 11, 22, \ldots, NN, each with one person living in it, and MM corridors connecting two different rooms. The ii-th corridor connects room UiU_i and room ViV_i with a length of WiW_i.

One day (we call this day 00), the KK people living in rooms A1,A2,,AKA_1, A_2, \ldots, A_K got (newly) infected with a virus. Furthermore, on the ii-th of the following DD days (1iD)(1\leq i\leq D), the infection spread as follows.

People who were infected at the end of the night of day (i1)(i-1) remained infected at the end of the night of day ii.
For those who were not infected, they were newly infected if and only if they were living in a room within a distance of XiX_i from at least one room where an infected person was living at the end of the night of day (i1)(i-1). Here, the distance between rooms PP and QQ is defined as the minimum possible sum of the lengths of the corridors when moving from room PP to room QQ using only corridors. If it is impossible to move from room PP to room QQ using only corridors, the distance is set to 1010010^{100}.

For each ii (1iN1\leq i\leq N), print the day on which the person living in room ii was newly infected. If they were not infected by the end of the night of day DD, print 1-1.

Constraints

  • 1N3×1051 \leq N\leq 3\times 10^5
  • 0M3×1050 \leq M\leq 3\times 10^5
  • 1Ui<ViN1 \leq U_i < V_i\leq N
  • All (Ui,Vi)(U_i,V_i) are different.
  • 1Wi1091\leq W_i\leq 10^9
  • 1KN1 \leq K\leq N
  • 1A1<A2<<AKN1\leq A_1<A_2<\cdots<A_K\leq N
  • 1D3×1051 \leq D\leq 3\times 10^5
  • 1Xi1091\leq X_i\leq 10^9
  • All input values are integers.

Input

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

NN MM

U1U_1 V1V_1 W1W_1

U2U_2 V2V_2 W2W_2

\vdots

UMU_M VMV_M WMW_M

KK

A1A_1 A2A_2 \ldots AKA_K

DD

X1X_1 X2X_2 \ldots XDX_D

Output

Print NN lines.
The ii-th line (1iN)(1\leq i\leq N) should contain the day on which the person living in room ii was newly infected.

Sample Input 1

4 4
1 2 2
2 3 1
2 4 3
3 4 2
1
1
2
3 3

Sample Output 1

0
1
1
2

The infection spreads as follows.

  • On the night of day 00, the person living in room 11 gets infected.
  • The distances between room 11 and rooms 2,3,42,3,4 are 2,3,52,3,5, respectively. Thus, since X1=3X_1=3, the people living in rooms 22 and 33 are newly infected on the night of day 11.
  • The distance between rooms 33 and 44 is 22. Thus, since X2=3X_2=3, the person living in room 44 also gets infected on the night of day 22.

Therefore, the people living in rooms 1,2,3,41,2,3,4 were newly infected on days 0,1,1,20,1,1,2, respectively, so print 0,1,1,20,1,1,2 in this order on separate lines.

Sample Input 2

7 7
1 2 2
2 3 3
3 4 1
4 5 1
5 6 3
3 7 1
4 7 1
2
1 6
2
2 3

Sample Output 2

0
1
2
-1
2
0
-1

Sample Input 3

5 1
1 2 5
2
1 3
3
3 7 5

Sample Output 3

0
2
0
-1
-1

Note that it is not always possible to move between any two rooms using only corridors.

update @ 2024/3/10 08:42:17