Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
英小文字からなる文字列 S が与えられます。ここで S の長さは 3 以上 100 以下です。
S はある 1 文字を除いて全て同じ文字で構成されています。
他のどの文字とも異なる文字は前から何文字目でしょうか。
制約
- S は 2 種類の英小文字からなる長さ 3 以上 100 以下の文字列
- S はある 1 文字を除いて全て同じ文字
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
yay
出力例 1
2
yay の 2 文字目は、1 文字目とも 3 文字目とも異なります。
入力例 2
egg
出力例 2
1
入力例 3
zzzzzwz
出力例 3
6
Score: 150 points
Problem Statement
You are given a string S consisting of lowercase English letters. The length of S is between 3 and 100, inclusive.
All characters but one of S are the same.
Find x such that the x-th character of S differs from all other characters.
Constraints
- S is a string of length between 3 and 100, inclusive, consisting of two different lowercase English letters.
- All characters but one of S are the same.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
yay
Sample Output 1
2
The second character of yay differs from the first and third characters.
Sample Input 2
egg
Sample Output 2
1
Sample Input 3
zzzzzwz
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋くんは A グラムの純金と B グラムの純銀 (0 \leq A,B,\ 0 \lt A+B) をよく溶かした上で混ぜ合わせ、新たな金属を生成しました。
生成された金属は「純金」「純銀」「合金」のいずれでしょうか?
なお、生成された金属は
- 0 \lt A かつ B=0 なら「純金」
- A=0 かつ 0 \lt B なら「純銀」
- 0 \lt A かつ 0 \lt B なら「合金」
であるとみなします。
制約
- 0 \leq A,B \leq 100
- 0 \lt A+B
- A,B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
生成された金属が「純金」なら Gold と、「純銀」なら Silver と、「合金」なら Alloy と出力せよ。
入力例 1
50 50
出力例 1
Alloy
0 \lt A かつ 0 \lt B であるため、生成された金属は「合金」です。
入力例 2
100 0
出力例 2
Gold
0 \lt A かつ B=0 であるため、生成された金属は「純金」です。
入力例 3
0 100
出力例 3
Silver
A=0 かつ 0 \lt B であるため、生成された金属は「純銀」です。
入力例 4
100 2
出力例 4
Alloy
Score : 100 points
Problem Statement
Takahashi melted and mixed A grams of gold and B grams of silver (0 \leq A,B,\ 0 \lt A+B) to produce new metal.
What metal did he produce: pure gold, pure silver, or an alloy?
Formally, the product is called as follows.
- Pure gold, if 0 \lt A and B=0.
- Pure silver, if A=0 and 0 \lt B.
- An alloy, if 0 \lt A and 0 \lt B.
Constraints
- 0 \leq A,B \leq 100
- 1 \leq A+B
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
If the product is pure gold, print Gold; if it is pure silver, print Silver; if it is an alloy, print Alloy.
Sample Input 1
50 50
Sample Output 1
Alloy
We have 0 \lt A and 0 \lt B, so the product is an alloy.
Sample Input 2
100 0
Sample Output 2
Gold
We have 0 \lt A and B=0, so the product is pure gold.
Sample Input 3
0 100
Sample Output 3
Silver
We have A=0 and 0 \lt B, so the product is pure silver.
Sample Input 4
100 2
Sample Output 4
Alloy
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
次の図に示す、各マスが黒または白に塗られた縦 15 行 \times 横 15 列のグリッドにおいて、 上から R 行目、左から C 列目のマスが何色かを出力して下さい。

制約
- 1 \leq R, C \leq 15
- R, C は整数
入力
入力は以下の形式で標準入力から与えられる。
R C
出力
図のグリッドにおいて上から R 行目、左から C 列目のマスが黒色の場合は black と、白色の場合は white と出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
3 5
出力例 1
black
図のグリッドにおいて上から 3 行目、左から 5 列目のマスは黒色です。
よって、black と出力します。
入力例 2
4 5
出力例 2
white
図のグリッドにおいて上から 4 行目、左から 5 列目のマスは白色です。
よって、white と出力します。
Score : 200 points
Problem Statement
Print the color of the cell at the R-th row from the top and C-th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.

Constraints
- 1 \leq R, C \leq 15
- R and C are integers.
Input
Input is given from Standard Input in the following format:
R C
Output
In the grid above, if the color of the cell at the R-th row from the top and C-th column from the left is black, then print black; if the cell is white, then print white. Note that the judge is case-sensitive.
Sample Input 1
3 5
Sample Output 1
black
In the grid above, the cell at the 3-rd row from the top and 5-th column from the left is black. Thus, black should be printed.
Sample Input 2
4 5
Sample Output 2
white
In the grid above, the cell at the 4-th row from the top and 5-th column from the left is white. Thus, white should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
N 個の整数 A_1,A_2,\dots,A_N が、 1 行に 1 つずつ、 N 行にわたって与えられます。但し、 N は入力では与えられません。
さらに、以下が保証されます。
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
A_N, A_{N-1},\dots,A_1 をこの順に出力してください。
制約
- 入力は全て整数
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 \vdots A_N
出力
A_N, A_{N-1},\dots,A_1 をこの順に、改行区切りで整数として出力せよ。
入力例 1
3 2 1 0
出力例 1
0 1 2 3
繰り返しになりますが、 N は入力では与えられないことに注意してください。
この入力においては N=4 で、 A=(3,2,1,0) です。
入力例 2
0
出力例 2
0
A=(0) です。
入力例 3
123 456 789 987 654 321 0
出力例 3
0 321 654 987 789 456 123
Score: 150 points
Problem Statement
You are given N integers A_1,A_2,\dots,A_N, one per line, over N lines. However, N is not given in the input.
Furthermore, the following is guaranteed:
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
Print A_N, A_{N-1},\dots,A_1 in this order.
Constraints
- All input values are integers.
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
Input
The input is given from Standard Input in the following format:
A_1 A_2 \vdots A_N
Output
Print A_N, A_{N-1}, \dots, A_1 in this order, as integers, separated by newlines.
Sample Input 1
3 2 1 0
Sample Output 1
0 1 2 3
Note again that N is not given in the input. Here, N=4 and A=(3,2,1,0).
Sample Input 2
0
Sample Output 2
0
A=(0).
Sample Input 3
123 456 789 987 654 321 0
Sample Output 3
0 321 654 987 789 456 123
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
列 S_n を次のように定義します。
- S_1 は 1 つの 1 からなる長さ 1 の列である。
- S_n (n は 2 以上の整数) は S_{n-1}, n, S_{n-1} をこの順につなげた列である。
たとえば S_2,S_3 は次のような列です。
- S_2 は S_1, 2, S_1 をこの順につなげた列なので 1,2,1 である。
- S_3 は S_2, 3, S_2 をこの順につなげた列なので 1,2,1,3,1,2,1 である。
N が与えられるので、列 S_N をすべて出力してください。
制約
- N は整数
- 1 \leq N \leq 16
入力
入力は以下の形式で標準入力から与えられる。
N
出力
S_N を空白区切りで出力せよ。
入力例 1
2
出力例 1
1 2 1
問題文の説明にある通り、S_2 は 1,2,1 となります。
入力例 2
1
出力例 2
1
入力例 3
4
出力例 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
S_4 は S_3,4,S_3 をこの順につなげた列です。
Score : 300 points
Problem Statement
We define sequences S_n as follows.
- S_1 is a sequence of length 1 containing a single 1.
- S_n (n is an integer greater than or equal to 2) is a sequence obtained by concatenating S_{n-1}, n, S_{n-1} in this order.
For example, S_2 and S_3 is defined as follows.
- S_2 is a concatenation of S_1, 2, and S_1, in this order, so it is 1,2,1.
- S_3 is a concatenation of S_2, 3, and S_2, in this order, so it is 1,2,1,3,1,2,1.
Given N, print the entire sequence S_N.
Constraints
- N is an integer.
- 1 \leq N \leq 16
Input
Input is given from Standard Input in the following format:
N
Output
Print S_N, with spaces in between.
Sample Input 1
2
Sample Output 1
1 2 1
As described in the Problem Statement, S_2 is 1,2,1.
Sample Input 2
1
Sample Output 2
1
Sample Input 3
4
Sample Output 3
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
- S_4 is a concatenation of S_3, 4, and S_3, in this order.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
二次元平面上に高橋君がいます。高橋君は原点から移動を N 回行いました。
N 回の移動は長さ N の文字列で表され、意味は次の通りです。
- i 回目の高橋君の移動後の座標は、移動前の座標を (x,y) として、
- S の i 文字目が
Rであるとき (x+1,y) - S の i 文字目が
Lであるとき (x-1,y) - S の i 文字目が
Uであるとき (x,y+1) - S の i 文字目が
Dであるとき (x,y-1)
- S の i 文字目が
N 回の移動 (始点と終点を含む) で、高橋君が同じ座標にいたことがあるかどうかを判定してください。
制約
- 1 \leq N \leq 2\times 10^5
- N は整数
- S は
R,L,U,Dのみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
N 回の移動 (始点と終点を含む) で、高橋君が同じ座標にいたことがあれば Yes、なければ No と出力せよ。
入力例 1
5 RLURU
出力例 1
Yes
高橋君のいる座標は (0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2) と変化します。
入力例 2
20 URDDLLUUURRRDDDDLLLL
出力例 2
No
Score : 300 points
Problem Statement
Takahashi is on a two-dimensional plane. Starting from the origin, he made N moves.
The N moves are represented by a string of length N as described below:
-
Takahashi's coordinates after the i-th move are:
- (x+1,y) if the i-th character of S is
R; - (x-1,y) if the i-th character of S is
L; - (x,y+1) if the i-th character of S is
U; and - (x,y-1) if the i-th character of S is
D,
where (x,y) is his coordinates before the move.
- (x+1,y) if the i-th character of S is
Determine if Takahashi visited the same coordinates multiple times in the course of the N moves (including the starting and ending points).
Constraints
- 1 \leq N \leq 2\times 10^5
- N is an integer.
- S is a string of length N consisting of
R,L,U, andD.
Input
The input is given from Standard Input in the following format:
N S
Output
Print Yes if Takahashi visited the same coordinates multiple times in the course of the N moves; print No otherwise.
Sample Input 1
5 RLURU
Sample Output 1
Yes
Takahashi's coordinates change as follows: (0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2).
Sample Input 2
20 URDDLLUUURRRDDDDLLLL
Sample Output 2
No
Time Limit: 2.5 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
座標平面上に 1 から N の番号がついた N 人の人がいます。
人 1 は原点にいます。
次の形式の情報が M 個与えられます。
- 人 A_i から見て、人 B_i は、x 軸正方向に X_i、y 軸正方向に Y_i 離れた位置にいる
それぞれの人がいる座標を求めてください。一意に定まらないときはそのことを報告してください。
制約
- 1 \leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1\leq A_i, B_i \leq N
- A_i \neq B_i
- -10^9 \leq X_i,Y_i \leq 10^9
- 入力は全て整数である
- 与えられる情報は矛盾しない
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 X_1 Y_1 \vdots A_M B_M X_M Y_M
出力
N 行出力せよ。
人 i のいる座標が一意に定まらないとき、i 行目には undecidable と出力せよ。
人 i のいる座標が (s_i,t_i) と一意に定まるとき、i 行目には s_i,t_i をこの順に空白区切りで出力せよ。
入力例 1
3 2 1 2 2 1 1 3 -1 -2
出力例 1
0 0 2 1 -1 -2
3 人の位置関係は下図のようになっています。

入力例 2
3 2 2 1 -2 -1 2 3 -3 -3
出力例 2
0 0 2 1 -1 -2
3 人の位置関係は下図のようになっています。

入力例 3
5 7 1 2 0 0 1 2 0 0 2 3 0 0 3 1 0 0 2 1 0 0 3 2 0 0 4 5 0 0
出力例 3
0 0 0 0 0 0 undecidable undecidable
同じ情報が複数回与えられたり、同じ座標に複数の人がいることもあります。
Score : 400 points
Problem Statement
There are N people numbered 1 to N on a coordinate plane.
Person 1 is at the origin.
You are given M pieces of information in the following form:
- From person A_i's perspective, person B_i is X_i units away in the positive x-direction and Y_i units away in the positive y-direction.
Determine the coordinates of each person. If the coordinates of a person cannot be uniquely determined, report that fact.
Constraints
- 1 \leq N \leq 2\times 10^5
- 0 \leq M \leq 2\times 10^5
- 1\leq A_i, B_i \leq N
- A_i \neq B_i
- -10^9 \leq X_i,Y_i \leq 10^9
- All input values are integers.
- The given information is consistent.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 X_1 Y_1 \vdots A_M B_M X_M Y_M
Output
Print N lines.
If the coordinates of person i cannot be uniquely determined, the i-th line should contain undecidable.
If they can be uniquely determined as (s_i,t_i), the i-th line should contain s_i and t_i in this order, separated by a space.
Sample Input 1
3 2 1 2 2 1 1 3 -1 -2
Sample Output 1
0 0 2 1 -1 -2
The figure below shows the positional relationship of the three people.

Sample Input 2
3 2 2 1 -2 -1 2 3 -3 -3
Sample Output 2
0 0 2 1 -1 -2
The figure below shows the positional relationship of the three people.

Sample Input 3
5 7 1 2 0 0 1 2 0 0 2 3 0 0 3 1 0 0 2 1 0 0 3 2 0 0 4 5 0 0
Sample Output 3
0 0 0 0 0 0 undecidable undecidable
The same piece of information may be given multiple times, and multiple people may be at the same coordinates.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
縦 H 行、横 W 列のマス目があり、上から i \, (1 \leq i \leq H) 行目、左から j \, (1 \leq j \leq W) 列目のマスを (i, j) と表します。
各マスは「始点」「道」「障害物」のいずれかです。
マス (i, j) の状態は文字 C_{i, j} で表され、C_{i, j} = S なら始点、C_{i, j} = . なら道、C_{i, j} = # なら障害物です。始点のマスはただ一つ存在します。
始点のマスを出発し、上下または左右に隣接するマスに移動することを繰り返して、障害物のマスを通らずに始点のマスへ戻ってくるような長さ 4 以上の経路であって、最初と最後を除き同じマスを通らないようなものが存在するか判定してください。
より厳密には、以下の条件を満たす整数 n およびマスの列 (x_0, y_0), (x_1, y_1), \dots, (x_n, y_n) が存在するか判定してください。
- n \geq 4
- C_{x_0, y_0} = C_{x_n, y_n} =
S - 1 \leq i \leq n - 1 ならば C_{x_i, y_i} =
. - 1 \leq i \lt j \leq n - 1 ならば (x_i, y_i) \neq (x_j, y_j)
- 0 \leq i \leq n - 1 ならばマス (x_i, y_i) とマス (x_{i+1}, y_{i+1}) は上下または左右に隣接する
制約
- 4 \leq H \times W \leq 10^6
- H, W は 2 以上の整数
- C_{i, j} は
S、.、#のいずれか - C_{i, j} =
Sとなる (i, j) がただ一つ存在する
入力
入力は以下の形式で標準入力から与えられる。
H W
C_{1, 1} \ldots C_{1, W}
\vdots
C_{H, 1} \ldots C_{H, W}
出力
問題文の条件を満たす経路が存在するならば Yes を、存在しないならば No を出力せよ。
入力例 1
4 4 .... #.#. .S.. .##.
出力例 1
Yes
(3, 2) \rightarrow (2, 2) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (1, 4) \rightarrow (2, 4) \rightarrow (3, 4) \rightarrow (3, 3) \rightarrow (3, 2) という経路が条件を満たします。
入力例 2
2 2 S. .#
出力例 2
No
入力例 3
5 7 .#...#. ..#.#.. ...S... ..#.#.. .#...#.
出力例 3
No
Score : 500 points
Problem Statement
We have a grid with H rows from top to bottom and W columns from left to right. Let (i, j) denote the i-th row from the top (1 \leq i \leq H) and j-th column from the left (1 \leq j \leq W).
Each square is one of the following: the initial point, a road, and an obstacle.
A square (i, j) is represented by a character C_{i, j}. The square is the initial point if C_{i, j} = S, a road if C_{i, j} = ., and an obstacle if C_{i, j} = #. There is exactly one initial point.
Determine whether there is a path of length 4 or greater that starts at the initial point, repeats moving vertically or horizontally to an adjacent square, and returns to the initial point without going through an obstacle or visiting the same square multiple times except at the beginning and the end.
More formally, determine whether there are an integer n and a sequence of squares (x_0, y_0), (x_1, y_1), \dots, (x_n, y_n) that satisfy the following conditions.
- n \geq 4.
- C_{x_0, y_0} = C_{x_n, y_n} =
S. - If 1 \leq i \leq n - 1, then C_{x_i, y_i} =
.. - If 1 \leq i \lt j \leq n - 1, then (x_i, y_i) \neq (x_j, y_j).
- If 0 \leq i \leq n - 1, then square (x_i, y_i) and square (x_{i+1}, y_{i+1}) are vertically or horizontally adjacent to each other.
Constraints
- 4 \leq H \times W \leq 10^6
- H and W are integers greater than or equal to 2.
- C_{i, j} is
S,., or#. - There is exactly one (i, j) such that C_{i, j} =
S.
Input
The input is given from Standard Input in the following format:
H W
C_{1, 1} \ldots C_{1, W}
\vdots
C_{H, 1} \ldots C_{H, W}
Output
If there is a path that satisfies the conditions in the Problem Statement, print Yes; otherwise, print No.
Sample Input 1
4 4 .... #.#. .S.. .##.
Sample Output 1
Yes
The path (3, 2) \rightarrow (2, 2) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (1, 4) \rightarrow (2, 4) \rightarrow (3, 4) \rightarrow (3, 3) \rightarrow (3, 2) satisfies the conditions.
Sample Input 2
2 2 S. .#
Sample Output 2
No
Sample Input 3
5 7 .#...#. ..#.#.. ...S... ..#.#.. .#...#.
Sample Output 3
No
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
部屋 1, 部屋 2, \ldots, 部屋 N と番号づけられた N 個の部屋に人が 1 人ずつ住んでおり、 また、いくつかの相異なる 2 つの部屋の間は通路によって結ばれています。 通路は M 本あり、i 本目の通路は部屋 U_i と部屋 V_i を結んでおり、長さは W_i です。
ある日(これを 0 日目とします)の夜に、部屋 A_1,A_2,\ldots, A_K に住んでいる K 人がウイルスに(新しく)感染してしまいました。 さらにその後の D 日間で i 日目 (1\leq i\leq D) には次のように感染が広がりました。
(i-1) 日目の夜の時点で感染していた人は、i 日目の夜の時点でも感染していた。
そうでない人については、(i-1) 日目の夜の時点で感染していた人の住んでいる部屋のうちの少なくとも 1 つから 距離 X_i 以内の部屋に住んでいた時かつその時に限り、新しく感染した。 ここで、部屋 P,Q の間の距離は、部屋 P から 部屋 Q まで通路のみを使って移動する時に通る通路の長さの総和としてあり得る最小値として定義される。 ただし、部屋 P から 部屋 Q へ通路のみを使って移動する事ができない時、距離は 10^{100} とする。
各 i (1\leq i\leq N) について、部屋 i に住んでいる人がそれぞれ何日目の夜に(新しく)感染したか出力してください。ただし、D 日目の夜の時点で感染していない場合は -1 を出力してください。
制約
- 1 \leq N\leq 3\times 10^5
- 0 \leq M\leq 3\times 10^5
- 1 \leq U_i < V_i\leq N
- (U_i,V_i) はすべて異なる。
- 1\leq W_i\leq 10^9
- 1 \leq K\leq N
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1 \leq D\leq 3\times 10^5
- 1\leq X_i\leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M U_1 V_1 W_1 U_2 V_2 W_2 \vdots U_M V_M W_M K A_1 A_2 \ldots A_K D X_1 X_2 \ldots X_D
出力
N 行出力せよ。
i 行目 (1\leq i\leq N) には、部屋 i に住んでいる人が何日目の夜に(新しく)感染したか出力せよ。
入力例 1
4 4 1 2 2 2 3 1 2 4 3 3 4 2 1 1 2 3 3
出力例 1
0 1 1 2
次のように感染は広がります。
- 0 日目の夜、部屋 1 に住んでいる人が感染する。
- 部屋 1 と部屋 2,3,4 の間の距離はそれぞれ 2,3,5 である。よって、X_1=3 であるから、1 日目の夜、部屋 2,3 に住んでいる人が新しく感染する。
- 部屋 3 と部屋 4 の間の距離は 2 である。よって、X_2=3 であるから、2 日目の夜、部屋 4 に住んでいる人も感染する。
よって、部屋 1,2,3,4 に住んでいる人はそれぞれ 0,1,1,2 日目に新しく感染したため、0,1,1,2 をこの順で各行に出力します。
入力例 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
出力例 2
0 1 2 -1 2 0 -1
入力例 3
5 1 1 2 5 2 1 3 3 3 7 5
出力例 3
0 2 0 -1 -1
どの 2 つの部屋の間も通路のみを使って移動できるとは限らないことに注意してください。
Score : 550 points
Problem Statement
There are N rooms numbered 1, 2, \ldots, N, each with one person living in it, and M corridors connecting two different rooms. The i-th corridor connects room U_i and room V_i with a length of W_i.
One day (we call this day 0), the K people living in rooms A_1, A_2, \ldots, A_K got (newly) infected with a virus. Furthermore, on the i-th of the following D days (1\leq i\leq D), the infection spread as follows.
People who were infected at the end of the night of day (i-1) remained infected at the end of the night of day i.
For those who were not infected, they were newly infected if and only if they were living in a room within a distance of X_i from at least one room where an infected person was living at the end of the night of day (i-1). Here, the distance between rooms P and Q is defined as the minimum possible sum of the lengths of the corridors when moving from room P to room Q using only corridors. If it is impossible to move from room P to room Q using only corridors, the distance is set to 10^{100}.
For each i (1\leq i\leq N), print the day on which the person living in room i was newly infected. If they were not infected by the end of the night of day D, print -1.
Constraints
- 1 \leq N\leq 3\times 10^5
- 0 \leq M\leq 3\times 10^5
- 1 \leq U_i < V_i\leq N
- All (U_i,V_i) are different.
- 1\leq W_i\leq 10^9
- 1 \leq K\leq N
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1 \leq D\leq 3\times 10^5
- 1\leq X_i\leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M U_1 V_1 W_1 U_2 V_2 W_2 \vdots U_M V_M W_M K A_1 A_2 \ldots A_K D X_1 X_2 \ldots X_D
Output
Print N lines.
The i-th line (1\leq i\leq N) should contain the day on which the person living in room i 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 0, the person living in room 1 gets infected.
- The distances between room 1 and rooms 2,3,4 are 2,3,5, respectively. Thus, since X_1=3, the people living in rooms 2 and 3 are newly infected on the night of day 1.
- The distance between rooms 3 and 4 is 2. Thus, since X_2=3, the person living in room 4 also gets infected on the night of day 2.
Therefore, the people living in rooms 1,2,3,4 were newly infected on days 0,1,1,2, respectively, so print 0,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.