A - Speaker Volume

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は音響エンジニアです。彼はコンサート会場の音響設計を担当しています。

会場には数直線上に N 台のスピーカーが設置されており、観客席にある測定点で聞こえる音の強さを計算する必要があります。測定点の座標は P です。

i 番目のスピーカーは座標 X_i に設置されており、出力の強さは V_i です。スピーカーから発せられた音が測定点に届くときの強さは、出力の強さを測定点までの距離で割った値になります。すなわち、i 番目のスピーカーの音が測定点に届くときの強さは \frac{V_i}{|X_i - P|} です。

ただし、測定点と同じ座標にスピーカーがある場合(X_i = P の場合)、距離が 0 となり値が定義できないため、そのスピーカーは計算から除外します。

高橋君は、測定点で聞こえる音の強さの合計、すなわち X_i \neq P であるすべての i について \frac{V_i}{|X_i - P|} の総和を計算したいと考えています。この値を求めてください。

なお、計算対象となるスピーカーが 1 台も存在しない場合(すべてのスピーカーが測定点と同じ座標にある場合)、合計は 0 とします。

制約

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq P \leq 10^9
  • -10^9 \leq X_i \leq 10^9
  • 1 \leq V_i \leq 10^6
  • \displaystyle \sum_{i=1}^{N} V_i \leq 10^6
  • N, P, X_i, V_i はすべて整数
  • X_i = P となるスピーカーが存在する場合がある

入力

N P
X_1 V_1
X_2 V_2
\vdots
X_N V_N
  • 1 行目には、スピーカーの台数を表す整数 N と、測定点の座標を表す整数 P が、スペース区切りで与えられる。
  • 2 行目から (N + 1) 行目には、各スピーカーの情報が与えられる。
  • (1 + i) 行目には、i 番目のスピーカーの座標 X_i と出力の強さ V_i が、スペース区切りで与えられる。

出力

測定点で聞こえる音の強さの合計を 1 行で出力せよ。

なお、真の値との絶対誤差または相対誤差が 10^{-4} 以下であれば正解とみなす。


入力例 1

3 0
-2 4
1 3
0 5

出力例 1

5.00000000000000000000

入力例 2

4 -3
-3 10
-4 2
1 8
-1 6

出力例 2

7.00000000000000000000

入力例 3

10 7
-5 24
0 14
3 8
6 15
7 100
8 9
10 21
15 32
20 39
100 93

出力例 3

45.00000000000000000000

入力例 4

30 -1000000000
-1000000000 50000
-999999999 12000
-999999998 24000
-999999990 35000
-999999900 18000
-999999000 42000
-999990000 16000
-999900000 27000
-999000000 31000
-990000000 22000
-900000000 45000
-750000000 15000
-500000000 38000
-250000000 19000
-1 29000
0 33000
1 17000
100 26000
10000 14000
1000000 41000
100000000 23000
250000000 37000
500000000 11000
750000000 34000
900000000 21000
999000000 28000
999900000 13000
999999998 39000
999999999 20000
1000000000 43000

出力例 4

27723.90413112317764898762

入力例 5

1 1000000000
1000000000 1000000

出力例 5

0.00000000000000000000

Score : 200 pts

Problem Statement

Takahashi is an audio engineer. He is in charge of the acoustic design of a concert venue.

There are N speakers installed on a number line in the venue, and he needs to calculate the sound intensity heard at a measurement point in the audience area. The coordinate of the measurement point is P.

The i-th speaker is installed at coordinate X_i, and its output power is V_i. The sound intensity from a speaker when it reaches the measurement point is given by its output power divided by the distance to the measurement point. That is, the sound intensity reaching the measurement point from the i-th speaker is \frac{V_i}{|X_i - P|}.

However, if a speaker is at the exact same coordinate as the measurement point (i.e., X_i = P), the distance becomes 0 and the value is undefined, so that speaker is excluded from the calculation.

Takahashi wants to calculate the total sound intensity heard at the measurement point, which is the sum of \frac{V_i}{|X_i - P|} over all i such that X_i \neq P. Find this value.

If there are no speakers to include in the calculation (i.e., all speakers are located at the measurement point), the total sum is considered to be 0.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq P \leq 10^9
  • -10^9 \leq X_i \leq 10^9
  • 1 \leq V_i \leq 10^6
  • \displaystyle \sum_{i=1}^{N} V_i \leq 10^6
  • N, P, X_i, and V_i are all integers.
  • There may be speakers where X_i = P.

Input

N P
X_1 V_1
X_2 V_2
\vdots
X_N V_N
  • The first line contains an integer N, representing the number of speakers, and an integer P, representing the coordinate of the measurement point, separated by a space.
  • The 2-nd through (N + 1)-th lines contain information about each speaker.
  • The (1 + i)-th line contains the coordinate X_i and the output power V_i of the i-th speaker, separated by a space.

Output

Print the total sound intensity heard at the measurement point in a single line.

Your output will be considered correct if the absolute or relative error from the true value is at most 10^{-4}.


Sample Input 1

3 0
-2 4
1 3
0 5

Sample Output 1

5.00000000000000000000

Sample Input 2

4 -3
-3 10
-4 2
1 8
-1 6

Sample Output 2

7.00000000000000000000

Sample Input 3

10 7
-5 24
0 14
3 8
6 15
7 100
8 9
10 21
15 32
20 39
100 93

Sample Output 3

45.00000000000000000000

Sample Input 4

30 -1000000000
-1000000000 50000
-999999999 12000
-999999998 24000
-999999990 35000
-999999900 18000
-999999000 42000
-999990000 16000
-999900000 27000
-999000000 31000
-990000000 22000
-900000000 45000
-750000000 15000
-500000000 38000
-250000000 19000
-1 29000
0 33000
1 17000
100 26000
10000 14000
1000000 41000
100000000 23000
250000000 37000
500000000 11000
750000000 34000
900000000 21000
999000000 28000
999900000 13000
999999998 39000
999999999 20000
1000000000 43000

Sample Output 4

27723.90413112317764898762

Sample Input 5

1 1000000000
1000000000 1000000

Sample Output 5

0.00000000000000000000
B - Placement of Emergency Helicopters

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

ある地域には N 個の集落があり、集落 1 から集落 N まで番号が付けられています。各集落 i (1 \leq i \leq N) は二次元平面上の座標 (X_i, Y_i) に位置しています。なお、異なる集落が同じ座標に位置することもあり得ます。

この地域では、救急ヘリコプターの基地をいずれかの集落に設置することで、緊急時に各集落へ迅速に対応できるようにしています。高橋君はこの地域の防災担当者であり、基地の設置場所を Q 回にわたって検討しています。k 回目 (1 \leq k \leq Q) の検討では、基地を集落 C_k に設置した場合を考えます。なお、異なる検討で同じ集落が指定されることもあり得ます。

高橋君は、各検討において、基地から全ての集落(基地が設置された集落自身を含む)へのユークリッド距離の合計を求めたいと考えています。ただし、この地域の管理システムでは整数値のみを扱う仕様になっているため、各集落への距離をそれぞれ切り捨てて(すなわち床関数を適用して)から合計することにしています。

具体的には、基地が集落 C_k に設置されているとき、求める値は

\sum_{j=1}^{N} \lfloor \sqrt{(X_{C_k} - X_j)^2 + (Y_{C_k} - Y_j)^2} \rfloor

です。ここで \lfloor x \rfloorx を超えない最大の整数を表します。

各検討について、この値を求めてください。

制約

  • 1 \leq N \leq 2000
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq X_i \leq 10^4 \quad (1 \leq i \leq N)
  • 0 \leq Y_i \leq 10^4 \quad (1 \leq i \leq N)
  • 1 \leq C_k \leq N \quad (1 \leq k \leq Q)
  • 入力はすべて整数である。

入力

N Q
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
C_1
C_2
\vdots
C_Q
  • 1 行目には、集落の数 N と検討の回数 Q が、スペース区切りで与えられる。
  • 2 行目から N + 1 行目では、各集落の座標が与えられる。
  • 1 + i 行目 (1 \leq i \leq N) では、集落 i の座標 (X_i, Y_i) がスペース区切りで与えられる。
  • N + 2 行目から N + 1 + Q 行目では、各検討における基地の設置先が与えられる。
  • N + 1 + k 行目 (1 \leq k \leq Q) では、k 回目の検討で基地を設置する集落の番号 C_k が与えられる。

出力

Q 行出力せよ。k 行目 (1 \leq k \leq Q) には、k 回目の検討において基地を集落 C_k に設置したときの、基地から全集落へのユークリッド距離をそれぞれ切り捨てた値の合計を出力せよ。


入力例 1

3 3
0 0
3 4
6 0
1
2
3

出力例 1

11
10
11

入力例 2

4 6
0 0
0 0
1 1
2 0
1
2
3
4
1
3

出力例 2

3
3
3
5
3
3

入力例 3

10 12
0 0
10 0
0 10
10 10
5 5
20 5
5 20
30 40
100 100
100 101
1
5
8
9
10
2
3
4
6
7
5
1

出力例 3

414
370
467
1011
1015
385
383
353
382
378
370
414

入力例 4

30 40
0 0
10000 0
0 10000
10000 10000
5000 5000
2500 2500
7500 2500
2500 7500
7500 7500
123 456
789 1011
2022 3033
4044 5055
6066 7077
8088 9099
9999 1
1 9999
3333 6666
6666 3333
1111 2222
2222 1111
4444 8888
8888 4444
1357 2468
2468 1357
9753 8642
8642 9753
3141 5926
2718 2818
0 0
1
2
3
4
5
30
10
15
20
25
26
27
28
29
6
7
8
9
11
12
13
14
16
17
18
19
21
22
23
24
1
30
5
15
2
3
4
27
28
10

出力例 4

206587
246423
236562
251008
136292
206587
196720
204145
159503
156776
225203
223246
141236
140231
143297
172264
163495
175044
177934
143957
134085
156092
246387
236525
146824
154588
161857
177860
185101
154231
206587
206587
136292
204145
246423
236562
251008
223246
141236
196720

入力例 5

1 5
10000 10000
1
1
1
1
1

出力例 5

0
0
0
0
0

Score : 300 pts

Problem Statement

A certain region has N settlements, numbered from settlement 1 to settlement N. Each settlement i (1 \leq i \leq N) is located at coordinates (X_i, Y_i) on a two-dimensional plane. Note that different settlements may be located at the same coordinates.

In this region, an emergency helicopter base is to be established at one of the settlements so that each settlement can be quickly reached in case of emergency. Takahashi is the disaster prevention officer for this region and is considering the placement of the base Q times. In the k-th consideration (1 \leq k \leq Q), he considers the case where the base is established at settlement C_k. Note that the same settlement may be specified in different considerations.

For each consideration, Takahashi wants to compute the sum of Euclidean distances from the base to all settlements (including the settlement where the base is established itself). However, since the management system for this region is designed to handle only integer values, the distance to each settlement is truncated (i.e., the floor function is applied) before summing.

Specifically, when the base is established at settlement C_k, the value to be computed is

\sum_{j=1}^{N} \lfloor \sqrt{(X_{C_k} - X_j)^2 + (Y_{C_k} - Y_j)^2} \rfloor

where \lfloor x \rfloor denotes the largest integer not exceeding x.

For each consideration, compute this value.

Constraints

  • 1 \leq N \leq 2000
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq X_i \leq 10^4 \quad (1 \leq i \leq N)
  • 0 \leq Y_i \leq 10^4 \quad (1 \leq i \leq N)
  • 1 \leq C_k \leq N \quad (1 \leq k \leq Q)
  • All inputs are integers.

Input

N Q
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
C_1
C_2
\vdots
C_Q
  • The first line contains the number of settlements N and the number of considerations Q, separated by a space.
  • From the 2nd line to the (N + 1)-th line, the coordinates of each settlement are given.
  • The (1 + i)-th line (1 \leq i \leq N) contains the coordinates (X_i, Y_i) of settlement i, separated by a space.
  • From the (N + 2)-th line to the (N + 1 + Q)-th line, the base location for each consideration is given.
  • The (N + 1 + k)-th line (1 \leq k \leq Q) contains the settlement number C_k where the base is to be established in the k-th consideration.

Output

Output Q lines. The k-th line (1 \leq k \leq Q) should contain the sum of the truncated Euclidean distances from the base to all settlements when the base is established at settlement C_k in the k-th consideration.


Sample Input 1

3 3
0 0
3 4
6 0
1
2
3

Sample Output 1

11
10
11

Sample Input 2

4 6
0 0
0 0
1 1
2 0
1
2
3
4
1
3

Sample Output 2

3
3
3
5
3
3

Sample Input 3

10 12
0 0
10 0
0 10
10 10
5 5
20 5
5 20
30 40
100 100
100 101
1
5
8
9
10
2
3
4
6
7
5
1

Sample Output 3

414
370
467
1011
1015
385
383
353
382
378
370
414

Sample Input 4

30 40
0 0
10000 0
0 10000
10000 10000
5000 5000
2500 2500
7500 2500
2500 7500
7500 7500
123 456
789 1011
2022 3033
4044 5055
6066 7077
8088 9099
9999 1
1 9999
3333 6666
6666 3333
1111 2222
2222 1111
4444 8888
8888 4444
1357 2468
2468 1357
9753 8642
8642 9753
3141 5926
2718 2818
0 0
1
2
3
4
5
30
10
15
20
25
26
27
28
29
6
7
8
9
11
12
13
14
16
17
18
19
21
22
23
24
1
30
5
15
2
3
4
27
28
10

Sample Output 4

206587
246423
236562
251008
136292
206587
196720
204145
159503
156776
225203
223246
141236
140231
143297
172264
163495
175044
177934
143957
134085
156092
246387
236525
146824
154588
161857
177860
185101
154231
206587
206587
136292
204145
246423
236562
251008
223246
141236
196720

Sample Input 5

1 5
10000 10000
1
1
1
1
1

Sample Output 5

0
0
0
0
0
C - Watering the Flower Bed

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 366

問題文

高橋君は庭に N 個の花壇を一列に並べて管理しています。花壇には左から順に 1 から N までの番号が付けられており、水やりを行う前の時点で、花壇 i の水分量は C_i です。

高橋君は毎日の水やりを効率的に行うため、ホースを使って連続した範囲の花壇にまとめて水をやります。1 回の水やりで対象となる各花壇の水分量が増加する量は K であり、この値はすべての水やりで共通です。

高橋君はこれから Q 回の水やりを行います。j 回目 (1 \leq j \leq Q) の水やりでは、花壇 L_j から花壇 R_j まで(両端を含む)を対象とし、対象となる各花壇の水分量をそれぞれ K だけ増加させます。

すべての水やりが終わった後の、各花壇の水分量を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq C_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq L_j \leq R_j \leq N (1 \leq j \leq Q)
  • 入力はすべて整数

入力

N K Q
C_1 C_2 \cdots C_N
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q
  • 1 行目には、花壇の個数 N 、水やり 1 回あたりに対象の各花壇へ加える水分量 K 、水やりの回数 Q が、スペース区切りで与えられる。
  • 2 行目には、水やりを行う前の各花壇の水分量 C_1, C_2, \ldots, C_N が、スペース区切りで与えられる。
  • 3 行目から Q 行にわたって、各水やりの情報が与えられる。2 + j 行目 (1 \leq j \leq Q) には、j 回目の水やりで対象となる花壇の範囲の左端 L_j と右端 R_j が、スペース区切りで与えられる。

出力

すべての水やりが終わった後の各花壇の水分量を、花壇 1 から花壇 N の順にスペース区切りで 1 行に出力せよ。末尾に改行を出力すること。


入力例 1

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

出力例 1

4 8 9 7 5

入力例 2

7 10 4
0 5 3 8 2 6 1
1 4
3 7
2 5
4 4

出力例 2

10 25 33 48 22 16 11

入力例 3

10 1000000000 5
100 200 300 400 500 600 700 800 900 1000
1 10
3 8
5 5
1 5
6 10

出力例 3

2000000100 2000000200 3000000300 3000000400 4000000500 3000000600 3000000700 3000000800 2000000900 2000001000

Score : 366 pts

Problem Statement

Takahashi manages N flower beds arranged in a row in his garden. The flower beds are numbered from 1 to N from left to right, and before any watering is done, the moisture level of flower bed i is C_i.

To water his garden efficiently each day, Takahashi uses a hose to water a contiguous range of flower beds at once. Each watering increases the moisture level of each targeted flower bed by K, and this value is the same for all waterings.

Takahashi will perform Q waterings. In the j-th watering (1 \leq j \leq Q), he targets flower beds from L_j to R_j (inclusive), increasing the moisture level of each targeted flower bed by K.

Determine the moisture level of each flower bed after all waterings are completed.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq C_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq L_j \leq R_j \leq N (1 \leq j \leq Q)
  • All input values are integers

Input

N K Q
C_1 C_2 \cdots C_N
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q
  • The first line contains the number of flower beds N, the moisture amount K added to each targeted flower bed per watering, and the number of waterings Q, separated by spaces.
  • The second line contains the moisture levels C_1, C_2, \ldots, C_N of each flower bed before watering, separated by spaces.
  • The following Q lines contain the information for each watering. The (2 + j)-th line (1 \leq j \leq Q) contains the left endpoint L_j and right endpoint R_j of the range of flower beds targeted in the j-th watering, separated by spaces.

Output

Print the moisture levels of all flower beds after all waterings are completed, in order from flower bed 1 to flower bed N, separated by spaces, on a single line. Output a newline at the end.


Sample Input 1

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

Sample Output 1

4 8 9 7 5

Sample Input 2

7 10 4
0 5 3 8 2 6 1
1 4
3 7
2 5
4 4

Sample Output 2

10 25 33 48 22 16 11

Sample Input 3

10 1000000000 5
100 200 300 400 500 600 700 800 900 1000
1 10
3 8
5 5
1 5
6 10

Sample Output 3

2000000100 2000000200 3000000300 3000000400 4000000500 3000000600 3000000700 3000000800 2000000900 2000001000
D - Importance of Relay Cities

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は N 個の都市からなる国の交通網を調査しています。この国には M 本の一方通行の道路があり、道路 i は都市 u_i から都市 v_i へ向かう道路で、通行料は w_i です。同じ始点・終点の組を持つ道路は高々1本であり、自己ループ(始点と終点が同じ道路)は存在しません。

都市 s から都市 ts \neq t)への経路とは、都市の列 s = c_0, c_1, \ldots, c_l = tl \geq 1)であって、各 h = 0, 1, \ldots, l-1 について都市 c_h から都市 c_{h+1} への道路が存在するものを指します。ここで、経路中の同じ都市を複数回通ることも許されます。この経路のコストは、通過する各道路の通行料の総和、すなわち \displaystyle\sum_{h=0}^{l-1} w_{(c_h, c_{h+1})} です。ただし w_{(c_h, c_{h+1})} は都市 c_h から都市 c_{h+1} への道路の通行料を表します。

都市 s から都市 t への経路が1つ以上存在するとき、それらの経路の中でコストが最小のものを最短経路と呼び、そのコストを最短コスト d(s, t) と呼びます。最短経路は複数存在することもあります。

また、経路 c_0, c_1, \ldots, c_l において、始点 c_0 と終点 c_l を除いた頂点 c_1, c_2, \ldots, c_{l-1}l \geq 2 のとき)を、その経路の内部の頂点と呼びます。

高橋君は、各都市がどれほど中継地点として重要かを評価したいと考えています。都市 k1 \leq k \leq N)の重要度を次のように定義します。

都市の順序付きペア (i, j)1 \leq i, j \leq Ni, j, k はすべて相異なる)であって、以下の条件を満たすものの個数を、都市 k の重要度とする。


- 都市 i から都市 j への最短経路のうち、都市 k を内部の頂点として含むものが少なくとも1つ存在する。すなわち、ある最短経路 c_0, c_1, \ldots, c_l が存在して、ある h1 \leq h \leq l-1)について c_h = k となる。


順序付きペアであるため、ペア (i, j)(j, i) は区別して数える。また、都市 i から都市 j への経路が1つも存在しない場合、そのペア (i, j) はどの都市の重要度にも寄与しない。

都市 i から都市 j への最短経路が複数存在する場合、そのうち1つでも都市 k を内部の頂点として含んでいれば、ペア (i, j) は都市 k の重要度に数えます。

各都市 1, 2, \ldots, N について、それぞれの重要度を求めてください。

制約

  • 2 \leq N \leq 250
  • 0 \leq M \leq N(N-1)
  • 1 \leq u_i, v_i \leq N
  • u_i \neq v_i
  • 1 \leq w_i \leq 10^6
  • (u_i, v_i) の組はすべて異なる
  • 入力はすべて整数

入力

N M
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_M v_M w_M
  • 1 行目には、都市の数を表す整数 N と、道路の数を表す整数 M が、スペース区切りで与えられる。
  • 続く M 行のうち i 行目には、道路 i の始点 u_i、終点 v_i、通行料 w_i が、スペース区切りで与えられる。
  • これは都市 u_i から都市 v_i への通行料 w_i の一方通行の道路を表す。
  • 同じ (u_i, v_i) の組が複数回与えられることはない。
  • u_i \neq v_i である。

出力

N 行出力せよ。i 行目には、都市 i の重要度を出力せよ。


入力例 1

4 5
1 2 2
2 3 3
1 3 5
3 4 1
2 4 10

出力例 1

0
2
2
0

入力例 2

5 4
1 2 4
2 3 6
1 3 10
4 5 1

出力例 2

0
1
0
0
0

入力例 3

8 20
1 2 4
1 3 7
2 3 3
2 4 8
2 5 6
3 4 5
3 5 2
3 6 9
4 5 4
4 7 7
5 4 1
5 6 3
5 7 6
6 7 2
6 8 8
7 6 5
7 8 4
8 1 10
8 3 6
4 8 11

出力例 3

6
6
19
0
21
15
20
19

入力例 4

15 50
1 2 4
2 3 7
3 4 2
4 5 6
5 6 3
6 7 8
7 8 1
8 9 5
9 10 4
10 11 9
11 12 2
12 13 7
13 14 3
14 15 6
15 1 10
1 3 11
2 4 8
3 5 8
4 6 9
5 7 11
6 8 9
7 9 6
8 10 9
9 11 13
10 12 11
11 13 9
12 14 10
13 15 9
14 1 12
15 2 14
2 1 12
3 2 5
4 3 14
5 4 4
6 5 15
7 6 6
8 7 13
9 8 3
10 9 16
11 10 5
1 8 20
2 9 18
3 10 17
4 11 21
5 12 16
6 13 19
7 14 15
8 15 14
9 1 22
10 2 1000000

出力例 4

63
64
4
52
42
36
24
31
25
15
17
19
35
37
9

入力例 5

2 0

出力例 5

0
0

Score : 400 pts

Problem Statement

Takahashi is investigating the transportation network of a country consisting of N cities. In this country, there are M one-way roads. Road i goes from city u_i to city v_i with a toll of w_i. There is at most one road for each pair of start and end cities, and there are no self-loops (roads where the start and end cities are the same).

A path from city s to city t (s \neq t) refers to a sequence of cities s = c_0, c_1, \ldots, c_l = t (l \geq 1) such that for each h = 0, 1, \ldots, l-1, there exists a road from city c_h to city c_{h+1}. Here, passing through the same city multiple times in a path is allowed. The cost of this path is the sum of the tolls of all roads passed through, that is, \displaystyle\sum_{h=0}^{l-1} w_{(c_h, c_{h+1})}, where w_{(c_h, c_{h+1})} represents the toll of the road from city c_h to city c_{h+1}.

When there is at least one path from city s to city t, a path among them with the minimum cost is called a shortest path, and its cost is called the shortest cost d(s, t). There may be multiple shortest paths.

Also, in a path c_0, c_1, \ldots, c_l, the vertices c_1, c_2, \ldots, c_{l-1} (when l \geq 2), excluding the starting vertex c_0 and the ending vertex c_l, are called the internal vertices of the path.

Takahashi wants to evaluate how important each city is as a relay point. The importance of city k (1 \leq k \leq N) is defined as follows:

The importance of city k is the number of ordered pairs of cities (i, j) (1 \leq i, j \leq N, where i, j, and k are all distinct) that satisfy the following condition:


- There is at least one shortest path from city i to city j that contains city k as an internal vertex. That is, there exists a shortest path c_0, c_1, \ldots, c_l such that c_h = k for some h (1 \leq h \leq l-1).


Since these are ordered pairs, the pairs (i, j) and (j, i) are counted separately. Also, if there is no path from city i to city j, the pair (i, j) does not contribute to the importance of any city.

If there are multiple shortest paths from city i to city j, as long as at least one of them contains city k as an internal vertex, the pair (i, j) is counted toward the importance of city k.

Find the importance of each city 1, 2, \ldots, N.

Constraints

  • 2 \leq N \leq 250
  • 0 \leq M \leq N(N-1)
  • 1 \leq u_i, v_i \leq N
  • u_i \neq v_i
  • 1 \leq w_i \leq 10^6
  • All pairs (u_i, v_i) are distinct.
  • All input values are integers.

Input

N M
u_1 v_1 w_1
u_2 v_2 w_2
\vdots
u_M v_M w_M
  • The first line contains an integer N representing the number of cities, and an integer M representing the number of roads, separated by a space.
  • The i-th of the following M lines contains the starting city u_i, the ending city v_i, and the toll w_i of road i, separated by spaces.
  • This represents a one-way road from city u_i to city v_i with a toll of w_i.
  • The same pair (u_i, v_i) is not given multiple times.
  • u_i \neq v_i.

Output

Print N lines. The i-th line should contain the importance of city i.


Sample Input 1

4 5
1 2 2
2 3 3
1 3 5
3 4 1
2 4 10

Sample Output 1

0
2
2
0

Sample Input 2

5 4
1 2 4
2 3 6
1 3 10
4 5 1

Sample Output 2

0
1
0
0
0

Sample Input 3

8 20
1 2 4
1 3 7
2 3 3
2 4 8
2 5 6
3 4 5
3 5 2
3 6 9
4 5 4
4 7 7
5 4 1
5 6 3
5 7 6
6 7 2
6 8 8
7 6 5
7 8 4
8 1 10
8 3 6
4 8 11

Sample Output 3

6
6
19
0
21
15
20
19

Sample Input 4

15 50
1 2 4
2 3 7
3 4 2
4 5 6
5 6 3
6 7 8
7 8 1
8 9 5
9 10 4
10 11 9
11 12 2
12 13 7
13 14 3
14 15 6
15 1 10
1 3 11
2 4 8
3 5 8
4 6 9
5 7 11
6 8 9
7 9 6
8 10 9
9 11 13
10 12 11
11 13 9
12 14 10
13 15 9
14 1 12
15 2 14
2 1 12
3 2 5
4 3 14
5 4 4
6 5 15
7 6 6
8 7 13
9 8 3
10 9 16
11 10 5
1 8 20
2 9 18
3 10 17
4 11 21
5 12 16
6 13 19
7 14 15
8 15 14
9 1 22
10 2 1000000

Sample Output 4

63
64
4
52
42
36
24
31
25
15
17
19
35
37
9

Sample Input 5

2 0

Sample Output 5

0
0
E - Laser Pointer Experiment

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 466

問題文

高橋君は物理の実験で、レーザーポインターを使った光の直進性に関する実験を行っています。

実験台の上の二次元平面上に N 個のセンサーが配置されています。i 番目のセンサー (1 \leq i \leq N) は座標 (X_i, Y_i) に置かれています。同じ座標に複数のセンサーが配置されることもありますが、それぞれ別のセンサーとして扱います。

高橋君はレーザーポインターを使って、平面上にレーザー光線を一度だけ照射します。レーザー光線は平面上の直線(両方向に無限に伸びるもの)として表されます。高橋君はこの直線を、センサーの位置に関係なく、平面上の任意の直線から自由に選ぶことができます。

各センサーは、そのセンサーの位置から直線までの距離(点と直線の最短距離)が D 以下であるとき反応します。ここで D はセンサーが反応する距離の閾値です。

このとき、反応するセンサーの個数を最大化してください。すなわち、平面上の直線 \ell を一つ選んだとき、点 (X_i, Y_i) から直線 \ell までの距離が D 以下であるようなセンサー i の個数の最大値を求めてください。

制約

  • 1 \leq N \leq 200
  • 0 \leq D \leq 1000
  • -1000 \leq X_i \leq 1000 (1 \leq i \leq N)
  • -1000 \leq Y_i \leq 1000 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
  • 1 行目には、センサーの個数 N と、センサーが反応する距離の閾値 D が、スペース区切りで与えられる。
  • 2 行目から N+1 行目には、各センサーの座標が与えられる。i+1 行目 (1 \leq i \leq N) には、i 番目のセンサーの x 座標 X_iy 座標 Y_i が、スペース区切りで与えられる。

出力

高橋君が一度のレーザー照射で同時に反応させることができるセンサーの最大個数を 1 行で出力せよ。


入力例 1

5 1
0 0
1 0
2 1
3 3
0 2

出力例 1

4

入力例 2

6 0
0 0
1 1
2 2
0 2
2 0
1 0

出力例 2

3

入力例 3

20 2
-5 -6
-4 -3
-3 -3
-2 -1
-1 -2
0 1
1 0
2 2
3 4
4 3
5 6
6 5
7 7
8 10
10 8
-8 5
-6 8
3 -7
9 -4
0 0

出力例 3

16

入力例 4

60 4
-30 -62
-28 -55
-26 -51
-24 -49
-22 -43
-20 -41
-18 -34
-16 -33
-14 -27
-12 -25
-10 -18
-8 -17
-6 -11
-4 -9
-2 -2
0 -1
2 5
4 7
6 14
8 15
10 21
12 23
14 30
16 31
18 37
20 39
22 46
24 47
26 53
28 55
30 62
-50 40
-45 -10
-40 70
-35 0
-32 100
-25 80
-15 60
-5 50
5 -50
15 -60
25 -70
35 -80
45 10
50 -40
60 60
-60 -60
0 80
80 0
-80 0
0 -80
100 100
-100 100
100 -100
-100 -100
12 23
12 23
-20 -41
31 60
-31 -60

出力例 4

36

入力例 5

1 1000
-1000 1000

出力例 5

1

Score : 466 pts

Problem Statement

Takahashi is conducting a physics experiment on the straightness of light using a laser pointer.

There are N sensors placed on a two-dimensional plane. The i-th sensor (1 \leq i \leq N) is located at the coordinates (X_i, Y_i). Multiple sensors may be placed at the same coordinates, but they are treated as distinct sensors.

Takahashi will project a laser beam onto the plane exactly once. The laser beam is represented as a straight line on the plane (extending infinitely in both directions). Takahashi can freely choose this line from any possible line on the plane, regardless of the positions of the sensors.

Each sensor reacts if the distance from the sensor's position to the line (the shortest distance between a point and a line) is at most D. Here, D is the threshold distance for the sensors to react.

Your task is to maximize the number of reacting sensors. That is, find the maximum number of sensors i such that the distance from the point (X_i, Y_i) to a chosen line \ell is at most D, over all possible lines \ell on the plane.

Constraints

  • 1 \leq N \leq 200
  • 0 \leq D \leq 1000
  • -1000 \leq X_i \leq 1000 (1 \leq i \leq N)
  • -1000 \leq Y_i \leq 1000 (1 \leq i \leq N)
  • All input values are integers.

Input

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
  • The first line contains the number of sensors N and the threshold distance D for the sensors to react, separated by a space.
  • The next N lines, from the 2nd line to the (N+1)-th line, contain the coordinates of the sensors. The (i+1)-th line (1 \leq i \leq N) contains the x-coordinate X_i and the y-coordinate Y_i of the i-th sensor, separated by a space.

Output

Print the maximum number of sensors that Takahashi can simultaneously activate with a single laser projection in a single line.


Sample Input 1

5 1
0 0
1 0
2 1
3 3
0 2

Sample Output 1

4

Sample Input 2

6 0
0 0
1 1
2 2
0 2
2 0
1 0

Sample Output 2

3

Sample Input 3

20 2
-5 -6
-4 -3
-3 -3
-2 -1
-1 -2
0 1
1 0
2 2
3 4
4 3
5 6
6 5
7 7
8 10
10 8
-8 5
-6 8
3 -7
9 -4
0 0

Sample Output 3

16

Sample Input 4

60 4
-30 -62
-28 -55
-26 -51
-24 -49
-22 -43
-20 -41
-18 -34
-16 -33
-14 -27
-12 -25
-10 -18
-8 -17
-6 -11
-4 -9
-2 -2
0 -1
2 5
4 7
6 14
8 15
10 21
12 23
14 30
16 31
18 37
20 39
22 46
24 47
26 53
28 55
30 62
-50 40
-45 -10
-40 70
-35 0
-32 100
-25 80
-15 60
-5 50
5 -50
15 -60
25 -70
35 -80
45 10
50 -40
60 60
-60 -60
0 80
80 0
-80 0
0 -80
100 100
-100 100
100 -100
-100 -100
12 23
12 23
-20 -41
31 60
-31 -60

Sample Output 4

36

Sample Input 5

1 1000
-1000 1000

Sample Output 5

1