/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
高橋君はある地域の電力供給システムを管理しています。この地域には N 個の工場と K 個の発電所があり、それらが送電線で結ばれた送電ネットワークを構成しています。
地点は 1 から N + K まで番号付けされており、地点 1 から N が工場、地点 N + 1 から N + K が発電所に対応します。すなわち、工場 i(1 \leq i \leq N)は地点 i に、発電所 k(1 \leq k \leq K)は地点 N + k に位置します。
送電ネットワークは N + K 個の地点と、それらを結ぶ M 本の送電線から構成されます。各送電線 j(1 \leq j \leq M)は地点 U_j と地点 V_j を双方向に結んでおり、1日あたり最大 C_j メガワットの電力を送ることができます。具体的には、送電線 j を通じて地点 U_j から地点 V_j の方向に流れる電力量を f_j メガワットとしたとき、-C_j \leq f_j \leq C_j を満たす必要があります。ここで f_j > 0 は地点 U_j から地点 V_j への送電を、f_j < 0 は地点 V_j から地点 U_j への送電を意味します。
各発電所 k(1 \leq k \leq K)は、使用可能な間、1日あたり 0 以上 W_k メガワット以下の任意の量の電力を供給できます。各工場 i(1 \leq i \leq N)は、稼働のために1日あたり B_i メガワット以上の電力を受け取る必要があります。工場は B_i を超える電力を受け取ることも可能であり、余剰の電力が流入しても問題なく稼働します。
各地点では、電力の収支についてフロー保存則が成り立つ必要があります。地点 v における正味流入量 \mathrm{net}(v) を次のように定義します:
\mathrm{net}(v) = \sum_{\substack{j :\, V_j = v}} f_j - \sum_{\substack{j :\, U_j = v}} f_j
この式の意味を補足します。送電線 j について、f_j > 0 のとき電力は U_j から V_j へ流れるので、地点 V_j には f_j だけ流入し、地点 U_j からは f_j だけ流出します。f_j < 0 のときはその逆です。\mathrm{net}(v) は、地点 v に接続するすべての送電線について、地点 v への流入量の合計から流出量の合計を引いたものに等しくなります。
このとき、各地点で以下の条件を満たす必要があります。
- 地点 v が工場 i である場合:\mathrm{net}(v) \geq B_i。すなわち、工場 i には送電線を通じて正味 B_i メガワット以上の電力が流入する必要があります。
- 地点 v が使用可能な発電所 k である場合:-W_k \leq \mathrm{net}(v) \leq 0。すなわち、発電所 k は 0 以上 W_k 以下の電力を供給(送り出し)できます。供給した電力は地点から出て行くため、正味流入量は 0 以下になります。
- 地点 v が使用不能な発電所である場合:\mathrm{net}(v) = 0。電力の供給はできませんが、流入量と流出量が等しければよいので、送電線を通じて電力が通過する中継地点としては引き続き機能します。
初期状態では K 個の発電所はすべて使用可能ですが、初期状態においてすべての工場が必要な電力を確保できるとは限りません。
ところが、老朽化により発電所が順次故障して停止することが予想されています。具体的には、Q 個のイベントが順番に発生します。各イベント t(1 \leq t \leq Q)では、発電所 S_t が故障して使用不能になります。一度故障した発電所は以降ずっと使用不能のままです。なお、Q \leq K であり、すべての発電所が故障するとは限りません。
各イベントが発生した直後の状態において、すべての工場が必要な電力を確保して稼働を継続できるかどうかを判定してください。すなわち、その時点で使用可能な発電所のみを用いて、上記のフロー保存則を満たしつつ各工場 i に B_i メガワット以上の電力を届けるような電力の流し方が存在するかどうかを、各イベント後に回答してください。
制約
- 1 \leq N \leq 32
- 1 \leq K \leq 32
- 0 \leq M \leq 300
- 1 \leq B_i \leq 10^9(1 \leq i \leq N)
- 1 \leq W_k \leq 10^9(1 \leq k \leq K)
- 1 \leq U_j < V_j \leq N + K(1 \leq j \leq M)
- 1 \leq C_j \leq 10^9(1 \leq j \leq M)
- 同じ地点の組を結ぶ送電線は高々1本である(多重辺は存在しない)
- 1 \leq Q \leq K
- 1 \leq S_t \leq K(1 \leq t \leq Q)
- S_1, S_2, \ldots, S_Q はすべて異なる(同じ発電所が2回以上故障することはない)
- 入力はすべて整数である
入力
N K M B_1 B_2 \ldots B_N W_1 W_2 \ldots W_K U_1 V_1 C_1 U_2 V_2 C_2 \vdots U_M V_M C_M Q S_1 S_2 \vdots S_Q
- 1行目には、工場の数 N、発電所の数 K、送電線の数 M がスペース区切りで与えられる。
- 2行目には、各工場の1日あたりの必要電力 B_1, B_2, \ldots, B_N がスペース区切りで与えられる。工場 i は地点 i に対応する。
- 3行目には、各発電所の1日あたりの最大供給量 W_1, W_2, \ldots, W_K がスペース区切りで与えられる。発電所 k は地点 N + k に対応する。
- 続く M 行のうち j 行目(1 \leq j \leq M)には、送電線 j が結ぶ地点 U_j、V_j、および最大送電量 C_j がスペース区切りで与えられる。各送電線は双方向(無向辺)であり、U_j < V_j で与えられる。
- その次の行には、イベントの数 Q が与えられる。
- 続く Q 行のうち t 行目(1 \leq t \leq Q)には、イベント t で故障する発電所の番号 S_t(1 \leq S_t \leq K)が与えられる。発電所 S_t は地点 N + S_t に対応する。
出力
Q 行出力せよ。t 行目(1 \leq t \leq Q)には、イベント t の発生直後にすべての工場が必要電力を確保できる場合は Yes を、できない場合は No を出力せよ。
入力例 1
2 2 3 2 3 2 5 1 3 2 1 4 2 2 4 3 2 1 2
出力例 1
Yes No
入力例 2
2 2 3 3 3 6 6 1 2 2 1 3 6 2 4 3 1 2
出力例 2
No
入力例 3
4 3 10 3 4 2 5 7 4 7 1 5 3 2 5 4 1 6 3 3 6 2 4 6 2 2 7 3 3 7 3 4 7 5 5 6 4 6 7 4 3 2 1 3
出力例 3
Yes No No
入力例 4
6 5 19 2 4 3 5 4 3 5 4 6 7 8 1 7 3 1 9 2 2 7 4 2 10 2 3 8 3 3 9 3 4 10 5 4 11 3 5 8 2 5 11 4 6 9 2 6 11 3 7 8 3 8 9 3 9 10 3 10 11 3 7 9 4 7 10 4 8 11 2 4 2 1 5 4
出力例 4
Yes Yes No No
入力例 5
1 1 0 1 1 1 1
出力例 5
No
Score : 466 pts
Problem Statement
Takahashi manages the power supply system of a certain region. This region has N factories and K power plants, which are connected by transmission lines forming a power transmission network.
The locations are numbered from 1 to N + K, where locations 1 through N correspond to factories, and locations N + 1 through N + K correspond to power plants. Specifically, factory i (1 \leq i \leq N) is located at location i, and power plant k (1 \leq k \leq K) is located at location N + k.
The transmission network consists of N + K locations connected by M transmission lines. Each transmission line j (1 \leq j \leq M) bidirectionally connects location U_j and location V_j, and can transmit up to C_j megawatts of power per day. Specifically, letting f_j megawatts denote the amount of power flowing through transmission line j in the direction from location U_j to location V_j, the constraint -C_j \leq f_j \leq C_j must be satisfied. Here, f_j > 0 means power is transmitted from location U_j to location V_j, and f_j < 0 means power is transmitted from location V_j to location U_j.
Each power plant k (1 \leq k \leq K), while operational, can supply any amount of power between 0 and W_k megawatts per day. Each factory i (1 \leq i \leq N) needs to receive at least B_i megawatts of power per day to operate. A factory may receive more than B_i megawatts of power; it operates without issues even if surplus power flows in.
At each location, flow conservation must hold for the power balance. The net inflow \mathrm{net}(v) at location v is defined as follows:
\mathrm{net}(v) = \sum_{\substack{j :\, V_j = v}} f_j - \sum_{\substack{j :\, U_j = v}} f_j
To clarify the meaning of this formula: for transmission line j, when f_j > 0, power flows from U_j to V_j, so f_j flows into location V_j and f_j flows out of location U_j. When f_j < 0, the reverse holds. \mathrm{net}(v) equals the total inflow to location v minus the total outflow from location v, summed over all transmission lines connected to location v.
The following conditions must be satisfied at each location:
- If location v is factory i: \mathrm{net}(v) \geq B_i. That is, a net inflow of at least B_i megawatts must flow into factory i through the transmission lines.
- If location v is an operational power plant k: -W_k \leq \mathrm{net}(v) \leq 0. That is, power plant k can supply between 0 and W_k megawatts of power. Since the supplied power leaves the location, the net inflow is non-positive.
- If location v is a non-operational power plant: \mathrm{net}(v) = 0. It cannot supply power, but as long as inflow equals outflow, it can still function as a relay point through which power passes via transmission lines.
Initially, all K power plants are operational, but it is not guaranteed that all factories can secure the necessary power even in the initial state.
However, due to aging, power plants are expected to fail and shut down sequentially. Specifically, Q events occur in order. At each event t (1 \leq t \leq Q), power plant S_t fails and becomes non-operational. Once a power plant fails, it remains non-operational permanently. Note that Q \leq K, and not all power plants necessarily fail.
For the state immediately after each event occurs, determine whether all factories can secure the necessary power and continue operating. That is, after each event, answer whether there exists a way to route power such that, using only the currently operational power plants, the flow conservation conditions are satisfied and at least B_i megawatts of power is delivered to each factory i.
Constraints
- 1 \leq N \leq 32
- 1 \leq K \leq 32
- 0 \leq M \leq 300
- 1 \leq B_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq W_k \leq 10^9 (1 \leq k \leq K)
- 1 \leq U_j < V_j \leq N + K (1 \leq j \leq M)
- 1 \leq C_j \leq 10^9 (1 \leq j \leq M)
- There is at most one transmission line between any pair of locations (no multi-edges exist)
- 1 \leq Q \leq K
- 1 \leq S_t \leq K (1 \leq t \leq Q)
- S_1, S_2, \ldots, S_Q are all distinct (no power plant fails more than once)
- All input values are integers
Input
N K M B_1 B_2 \ldots B_N W_1 W_2 \ldots W_K U_1 V_1 C_1 U_2 V_2 C_2 \vdots U_M V_M C_M Q S_1 S_2 \vdots S_Q
- The first line contains the number of factories N, the number of power plants K, and the number of transmission lines M, separated by spaces.
- The second line contains the daily power requirements B_1, B_2, \ldots, B_N of each factory, separated by spaces. Factory i corresponds to location i.
- The third line contains the maximum daily supply W_1, W_2, \ldots, W_K of each power plant, separated by spaces. Power plant k corresponds to location N + k.
- The following M lines, where the j-th line (1 \leq j \leq M), contains the locations U_j, V_j connected by transmission line j, and the maximum transmission capacity C_j, separated by spaces. Each transmission line is bidirectional (undirected edge), and is given with U_j < V_j.
- The next line contains the number of events Q.
- The following Q lines, where the t-th line (1 \leq t \leq Q), contains the number S_t (1 \leq S_t \leq K) of the power plant that fails in event t. Power plant S_t corresponds to location N + S_t.
Output
Output Q lines. The t-th line (1 \leq t \leq Q) should contain Yes if all factories can secure the necessary power immediately after event t occurs, and No otherwise.
Sample Input 1
2 2 3 2 3 2 5 1 3 2 1 4 2 2 4 3 2 1 2
Sample Output 1
Yes No
Sample Input 2
2 2 3 3 3 6 6 1 2 2 1 3 6 2 4 3 1 2
Sample Output 2
No
Sample Input 3
4 3 10 3 4 2 5 7 4 7 1 5 3 2 5 4 1 6 3 3 6 2 4 6 2 2 7 3 3 7 3 4 7 5 5 6 4 6 7 4 3 2 1 3
Sample Output 3
Yes No No
Sample Input 4
6 5 19 2 4 3 5 4 3 5 4 6 7 8 1 7 3 1 9 2 2 7 4 2 10 2 3 8 3 3 9 3 4 10 5 4 11 3 5 8 2 5 11 4 6 9 2 6 11 3 7 8 3 8 9 3 9 10 3 10 11 3 7 9 4 7 10 4 8 11 2 4 2 1 5 4
Sample Output 4
Yes Yes No No
Sample Input 5
1 1 0 1 1 1 1
Sample Output 5
No