/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君は、山岳地帯の地形シミュレーションを行っています。
山岳地帯には N 個の地点があり、各地点には番号 1 から N が付けられています。地点 i の標高は H_i であり、初期時点で W_i リットルの雨水が溜まっています。
地点同士は M 本の水路で結ばれています。j 番目の水路は地点 U_j と地点 V_j を双方向に結んでいます。水は標高が高い地点から低い地点へのみ流れます。すなわち、水路で結ばれた2地点の標高が等しい場合、その水路を通じて水は流れません。
ある地点 v に対し、水路で直接結ばれた地点のうち標高が v より厳密に低い地点を、v の下流隣接地点と呼ぶことにします。
高橋君は、K 個の地点にダムを設置しました(K = 0 の場合、ダムは1つも設置されません)。ダムが設置された地点の番号は S_1, S_2, \ldots, S_K です。ダムが設置された地点では、水路を通じて他の地点から水が流入することはありますが、その地点から水が流れ出すことは一切ありません。
各地点の水の流出は、以下の手順で処理されます。
- すべての地点を標高の高い順に並べます。標高が同じ地点間では水が流れないため、同じ標高の地点同士の順序は任意で構いません(処理順序によって結果は変わりません)。
- この順に各地点を1つずつ処理します。処理対象の地点を v とし、v に現在溜まっている水量を w リットルとします。
- v にダムが設置されている場合:何もしません。w リットルの水はすべてそのまま v に残ります。
- v にダムが設置されておらず、下流隣接地点が d 個(d \geq 1)存在する場合:v に溜まっている w リットルの水はすべて流れ出します。流れ出す水は d 個の下流隣接地点に均等に分配され、各下流隣接地点にそれぞれ \frac{w}{d} リットルの水が流れ込みます(下流隣接地点にダムが設置されていてもそこへ流れ込みます)。流出後、v の水量は 0 になります。
- v にダムが設置されておらず、下流隣接地点が存在しない場合(水路が1本も接続されていない孤立した地点や、接続されたすべての地点の標高が v 以上である地点を含む):水はそのまま v に残ります。
ある地点の流出処理で下流隣接地点に水が流入した場合、その水は即座にその地点に蓄積され、その地点自身が処理される際にまとめて扱われます。
すべての流出処理が完了した後、各地点に残っている水量を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 0 \leq K \leq N
- 1 \leq H_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq W_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq U_j < V_j \leq N (1 \leq j \leq M)
- 同じ地点の組を結ぶ水路は高々 1 本である(多重辺はない)
- 1 \leq S_k \leq N (1 \leq k \leq K)
- S_1, S_2, \ldots, S_K はすべて異なる
- 入力はすべて整数で与えられる
入力
N M K H_1 H_2 \ldots H_N W_1 W_2 \ldots W_N U_1 V_1 U_2 V_2 \vdots U_M V_M S_1 S_2 \ldots S_K
- 1 行目には、地点の数 N、水路の数 M、ダムが設置された地点の数 K が、スペース区切りで与えられる。
- 2 行目には、各地点の標高 H_1, H_2, \ldots, H_N が、スペース区切りで与えられる。
- 3 行目には、各地点の初期水量 W_1, W_2, \ldots, W_N が、スペース区切りで与えられる。
- 続く M 行にわたり、各水路の情報が与えられる。そのうち j 行目(入力全体の 3 + j 行目)には、j 番目の水路が結ぶ地点 U_j と V_j がスペース区切りで与えられる。
- K \geq 1 の場合、最後の行にダムが設置された地点の番号 S_1, S_2, \ldots, S_K がスペース区切りで与えられる。K = 0 の場合、この行は存在しない。
出力
すべての流出処理が完了した後の各地点の水量を、地点 1 から地点 N の順にスペース区切りで 1 行で出力せよ。均等分配により水量が整数にならない場合があるため、小数で出力してもよい。出力の各値について、真の値との絶対誤差が 10^{-6} 以内、または真の値が 0 でないとき相対誤差が 10^{-6} 以内であれば正解とする。
入力例 1
4 4 0 10 20 5 5 0 12 0 0 1 2 1 3 2 3 2 4
出力例 1
0.0000000000 0.0000000000 8.0000000000 4.0000000000
入力例 2
3 2 1 30 20 10 6 0 0 1 2 2 3 2
出力例 2
0.0000000000 6.0000000000 0.0000000000
入力例 3
6 7 1 50 40 40 30 20 10 18 6 0 0 0 0 1 2 1 3 2 4 2 5 3 5 4 6 5 6 5
出力例 3
0.0000000000 0.0000000000 0.0000000000 0.0000000000 16.5000000000 7.5000000000
入力例 4
8 10 2 100 80 80 60 50 50 30 10 24 0 0 0 12 0 0 0 1 2 1 3 2 4 3 4 3 5 4 6 4 7 5 7 6 8 7 8 4 6
出力例 4
0.0000000000 0.0000000000 0.0000000000 18.0000000000 0.0000000000 0.0000000000 0.0000000000 18.0000000000
入力例 5
1 0 0 1000000000 999999999
出力例 5
999999999.0000000000
Score : 300 pts
Problem Statement
Takahashi is performing a terrain simulation of a mountainous area.
The mountainous area has N locations, each numbered from 1 to N. Location i has an elevation of H_i and initially holds W_i liters of rainwater.
The locations are connected by M channels. The j-th channel bidirectionally connects location U_j and location V_j. Water flows only from locations with higher elevation to locations with lower elevation. That is, if two locations connected by a channel have the same elevation, water does not flow through that channel.
For a location v, among the locations directly connected to v by a channel, those with elevation strictly lower than v are called the downstream neighbors of v.
Takahashi has installed dams at K locations (if K = 0, no dams are installed). The locations where dams are installed are numbered S_1, S_2, \ldots, S_K. At a location where a dam is installed, water may flow in from other locations through channels, but no water ever flows out from that location.
The water outflow from each location is processed according to the following procedure:
- Sort all locations in decreasing order of elevation. Since water does not flow between locations of the same elevation, the ordering among locations with the same elevation is arbitrary (the result does not depend on the processing order).
- Process each location one by one in this order. Let v be the location being processed, and let w liters be the amount of water currently accumulated at v.
- If a dam is installed at v: Do nothing. All w liters of water remain at v.
- If no dam is installed at v, and there are d downstream neighbors (d \geq 1): All w liters of water at v flow out. The outflowing water is distributed equally among the d downstream neighbors, with each downstream neighbor receiving \frac{w}{d} liters of water (water flows into a downstream neighbor even if a dam is installed there). After the outflow, the water amount at v becomes 0.
- If no dam is installed at v, and there are no downstream neighbors (including isolated locations with no connected channels, or locations where all connected locations have elevation greater than or equal to v): The water remains at v as is.
When water flows into a downstream neighbor during the outflow processing of some location, that water is immediately accumulated at the downstream neighbor and is handled collectively when that downstream neighbor itself is processed.
After all outflow processing is complete, determine the amount of water remaining at each location.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 0 \leq K \leq N
- 1 \leq H_i \leq 10^9 (1 \leq i \leq N)
- 0 \leq W_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq U_j < V_j \leq N (1 \leq j \leq M)
- There is at most one channel connecting the same pair of locations (no multi-edges)
- 1 \leq S_k \leq N (1 \leq k \leq K)
- S_1, S_2, \ldots, S_K are all distinct
- All input values are integers
Input
N M K H_1 H_2 \ldots H_N W_1 W_2 \ldots W_N U_1 V_1 U_2 V_2 \vdots U_M V_M S_1 S_2 \ldots S_K
- The first line contains the number of locations N, the number of channels M, and the number of locations with dams K, separated by spaces.
- The second line contains the elevations H_1, H_2, \ldots, H_N of each location, separated by spaces.
- The third line contains the initial water amounts W_1, W_2, \ldots, W_N of each location, separated by spaces.
- The following M lines contain the channel information. The j-th of these lines (line 3 + j of the entire input) contains the locations U_j and V_j connected by the j-th channel, separated by a space.
- If K \geq 1, the last line contains the location numbers S_1, S_2, \ldots, S_K where dams are installed, separated by spaces. If K = 0, this line does not exist.
Output
Output the water amounts at each location after all outflow processing is complete, from location 1 to location N, separated by spaces on a single line. Since equal distribution may result in non-integer water amounts, decimal output is acceptable. For each output value, the answer is considered correct if the absolute error from the true value is at most 10^{-6}, or if the true value is non-zero and the relative error is at most 10^{-6}.
Sample Input 1
4 4 0 10 20 5 5 0 12 0 0 1 2 1 3 2 3 2 4
Sample Output 1
0.0000000000 0.0000000000 8.0000000000 4.0000000000
Sample Input 2
3 2 1 30 20 10 6 0 0 1 2 2 3 2
Sample Output 2
0.0000000000 6.0000000000 0.0000000000
Sample Input 3
6 7 1 50 40 40 30 20 10 18 6 0 0 0 0 1 2 1 3 2 4 2 5 3 5 4 6 5 6 5
Sample Output 3
0.0000000000 0.0000000000 0.0000000000 0.0000000000 16.5000000000 7.5000000000
Sample Input 4
8 10 2 100 80 80 60 50 50 30 10 24 0 0 0 12 0 0 0 1 2 1 3 2 4 3 4 3 5 4 6 4 7 5 7 6 8 7 8 4 6
Sample Output 4
0.0000000000 0.0000000000 0.0000000000 18.0000000000 0.0000000000 0.0000000000 0.0000000000 18.0000000000
Sample Input 5
1 0 0 1000000000 999999999
Sample Output 5
999999999.0000000000