Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は料理コンテストの審査員を務めています。このコンテストには N 人のシェフが参加し、それぞれのシェフには 1 から N までの番号が付けられています。
コンテストでは M 種類の食材が用いられ、食材には 1 から M までの番号が付けられています。シェフ i は C_i 種類の食材を得意としており、得意とする食材の番号は T_{i,1}, T_{i,2}, \ldots, T_{i,C_i} です。ただし C_i = 0 のとき、シェフ i は得意とする食材を持ちません。
コンテストの予選の結果、シェフ i は得点 V_i を獲得しました。N 人のシェフを以下の規則で順位付けし、1 位から K 位までの K 人が決勝に進出します。
- 得点が高いシェフほど上位(順位の数値が小さい)とする。
- 得点が同じシェフ同士では、シェフ番号が小さい方を上位とする。
この規則により、すべてのシェフの順位は一意に定まり、決勝に進出する K 人も一意に定まります。
決勝では、進出した K 人のシェフ全員が共通して得意とする食材のみを使った料理を作ることになっています。すなわち、ある食材が決勝で使えるのは、決勝に進出した K 人のシェフ全員がその食材を得意としている場合に限ります。
高橋君のために、決勝に進出した K 人全員が共通して得意とする食材の数を求めてください。該当する食材がない場合は 0 を出力してください。
制約
- 1 \leq K \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 0 \leq C_i \leq M
- \sum_{i=1}^{N} C_i \leq 2 \times 10^5
- 1 \leq V_i \leq 10^9
- 1 \leq T_{i,j} \leq M
- 各シェフ i について、T_{i,1}, T_{i,2}, \ldots, T_{i,C_i} はすべて相異なる
- 入力はすべて整数
入力
N M K
V_1 C_1 T_{1,1} T_{1,2} \ldots T_{1,C_1}
V_2 C_2 T_{2,1} T_{2,2} \ldots T_{2,C_2}
\vdots
V_N C_N T_{N,1} T_{N,2} \ldots T_{N,C_N}
- 第 1 行には、シェフの人数 N、食材の種類数 M、決勝進出者数 K がスペース区切りで与えられる。
- 続く N 行のうち i 行目(1 \leq i \leq N)には、まずシェフ i の得点 V_i と、シェフ i が得意とする食材の数 C_i がスペース区切りで与えられる。C_i \geq 1 の場合は、同じ行に続けて得意とする食材の番号 T_{i,1}, T_{i,2}, \ldots, T_{i,C_i} がスペース区切りで与えられる。C_i = 0 の場合は、その行には V_i と C_i の 2 つの値のみが記載される。
出力
決勝に進出した K 人全員が共通して得意とする食材の数を 1 行で出力せよ。
入力例 1
3 5 2 100 3 1 2 3 80 4 1 2 4 5 90 2 1 2
出力例 1
2
入力例 2
5 6 3 50 2 1 3 100 3 1 2 3 100 4 1 2 3 4 75 3 2 3 5 60 0
出力例 2
2
入力例 3
10 8 4 500 5 1 2 3 4 5 450 4 1 2 3 6 480 6 1 2 3 4 5 6 300 3 1 2 7 520 4 1 2 3 8 200 2 1 2 490 5 1 2 3 5 7 350 4 2 3 4 5 400 3 1 3 4 100 1 1
出力例 3
3
Score : 266 pts
Problem Statement
Takahashi is serving as a judge for a cooking contest. N chefs are participating in this contest, and each chef is assigned a number from 1 to N.
The contest uses M types of ingredients, numbered from 1 to M. Chef i specializes in C_i types of ingredients, and the numbers of the ingredients they specialize in are T_{i,1}, T_{i,2}, \ldots, T_{i,C_i}. When C_i = 0, chef i has no ingredients they specialize in.
As a result of the contest's preliminary round, chef i earned a score of V_i. The N chefs are ranked according to the following rules, and the top K chefs (ranked 1st through Kth) advance to the finals.
- A chef with a higher score is ranked higher (i.e., has a smaller rank number).
- Among chefs with the same score, the chef with the smaller chef number is ranked higher.
Under these rules, the ranking of all chefs is uniquely determined, and the K chefs who advance to the finals are also uniquely determined.
In the finals, the K advancing chefs will cook dishes using only ingredients that all of them commonly specialize in. That is, an ingredient can be used in the finals only if all K chefs who advanced to the finals specialize in that ingredient.
For Takahashi, find the number of ingredients that all K chefs advancing to the finals commonly specialize in. If there are no such ingredients, output 0.
Constraints
- 1 \leq K \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 0 \leq C_i \leq M
- \sum_{i=1}^{N} C_i \leq 2 \times 10^5
- 1 \leq V_i \leq 10^9
- 1 \leq T_{i,j} \leq M
- For each chef i, T_{i,1}, T_{i,2}, \ldots, T_{i,C_i} are all distinct
- All input values are integers
Input
N M K
V_1 C_1 T_{1,1} T_{1,2} \ldots T_{1,C_1}
V_2 C_2 T_{2,1} T_{2,2} \ldots T_{2,C_2}
\vdots
V_N C_N T_{N,1} T_{N,2} \ldots T_{N,C_N}
- The first line contains the number of chefs N, the number of ingredient types M, and the number of finalists K, separated by spaces.
- In the following N lines, the i-th line (1 \leq i \leq N) first contains chef i's score V_i and the number of ingredients C_i that chef i specializes in, separated by spaces. If C_i \geq 1, the ingredient numbers T_{i,1}, T_{i,2}, \ldots, T_{i,C_i} follow on the same line, separated by spaces. If C_i = 0, that line contains only the two values V_i and C_i.
Output
Output on a single line the number of ingredients that all K chefs advancing to the finals commonly specialize in.
Sample Input 1
3 5 2 100 3 1 2 3 80 4 1 2 4 5 90 2 1 2
Sample Output 1
2
Sample Input 2
5 6 3 50 2 1 3 100 3 1 2 3 100 4 1 2 3 4 75 3 2 3 5 60 0
Sample Output 2
2
Sample Input 3
10 8 4 500 5 1 2 3 4 5 450 4 1 2 3 6 480 6 1 2 3 4 5 6 300 3 1 2 7 520 4 1 2 3 8 200 2 1 2 490 5 1 2 3 5 7 350 4 2 3 4 5 400 3 1 3 4 100 1 1
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君はスポーツ分析の仕事をしています。ある大会では N 人の選手が参加しており、T ラウンドにわたって競技が行われました。ラウンド j(1 \leq j \leq T)における選手 i(1 \leq i \leq N)の得点を S_{j,i} とします。
高橋君は、ある選手が他の選手を圧倒的に上回ったラウンドを特定したいと考えています。具体的には、あるラウンドにおいて選手が「ずば抜けている」ことを次のように定義しました:
> ラウンド j において、選手 i 以外のすべての選手の得点の最大値を M_{j,i} とする。S_{j,i} \geq 2 \times M_{j,i} が成り立つとき、選手 i はラウンド j で「ずば抜けている」とする。
なお、すべての得点は 1 以上であるため、もし選手 i がラウンド j でずば抜けているならば、S_{j,i} はそのラウンドの最大得点であり、かつ他のどの選手の得点もその半分以下です。したがって、1 つのラウンドでずば抜けている選手は 高々 1 人 です。
T ラウンドのうち、ずば抜けている選手が存在するラウンドの数を求めてください。
制約
- 2 \leq N \leq 10^5
- 1 \leq T \leq 10^5
- N \times T \leq 10^6
- 1 \leq S_{j,i} \leq 10^9
- 入力はすべて整数である
入力
N T
S_{1,1} S_{1,2} \ldots S_{1,N}
S_{2,1} S_{2,2} \ldots S_{2,N}
\vdots
S_{T,1} S_{T,2} \ldots S_{T,N}
- 1 行目には、選手の数 N とラウンドの回数 T が空白区切りで与えられる。
- 続く T 行のうち j 行目(1 \leq j \leq T)には、ラウンド j における選手 1, 2, \ldots, N の得点 S_{j,1}, S_{j,2}, \ldots, S_{j,N} が空白区切りで与えられる。
出力
T ラウンドのうち、ずば抜けている選手が存在するラウンドの数を 1 行で出力せよ。
入力例 1
3 4 10 3 4 5 6 5 1 1 3 7 4 4
出力例 1
2
入力例 2
3 3 5 6 5 10 8 9 100 99 100
出力例 2
0
入力例 3
5 6 100 200 50 30 40 90 80 85 88 91 1 1 1 1 1000000000 50 100 51 49 48 3 3 3 3 7 10 10 10 10 20
出力例 3
4
入力例 4
10 8 5 3 2 1 1 1 1 1 1 1 100 100 50 40 30 20 10 5 3 1 1000 400 499 500 200 100 50 25 12 6 7 7 7 7 7 7 7 7 7 14 999999999 500000000 1 1 1 1 1 1 1 1 1000000000 500000000 499999999 1 1 1 1 1 1 1 12 6 6 6 6 6 6 6 6 6 50 26 25 24 23 22 21 20 19 18
出力例 4
4
入力例 5
2 1 2 1
出力例 5
1
Score : 300 pts
Problem Statement
Takahashi works in sports analytics. In a certain tournament, N players participated and competed over T rounds. Let S_{j,i} denote the score of player i (1 \leq i \leq N) in round j (1 \leq j \leq T).
Takahashi wants to identify rounds where a certain player overwhelmingly outperformed the others. Specifically, he defined a player being "outstanding" in a round as follows:
> In round j, let M_{j,i} be the maximum score among all players other than player i. If S_{j,i} \geq 2 \times M_{j,i} holds, then player i is said to be "outstanding" in round j.
Since all scores are at least 1, if player i is outstanding in round j, then S_{j,i} is the maximum score in that round, and every other player's score is at most half of it. Therefore, there is at most one outstanding player in any single round.
Determine the number of rounds, out of the T rounds, in which an outstanding player exists.
Constraints
- 2 \leq N \leq 10^5
- 1 \leq T \leq 10^5
- N \times T \leq 10^6
- 1 \leq S_{j,i} \leq 10^9
- All input values are integers
Input
N T
S_{1,1} S_{1,2} \ldots S_{1,N}
S_{2,1} S_{2,2} \ldots S_{2,N}
\vdots
S_{T,1} S_{T,2} \ldots S_{T,N}
- The first line contains the number of players N and the number of rounds T, separated by a space.
- The following T lines, where the j-th line (1 \leq j \leq T) contains the scores S_{j,1}, S_{j,2}, \ldots, S_{j,N} of players 1, 2, \ldots, N in round j, separated by spaces.
Output
Print in one line the number of rounds, out of the T rounds, in which an outstanding player exists.
Sample Input 1
3 4 10 3 4 5 6 5 1 1 3 7 4 4
Sample Output 1
2
Sample Input 2
3 3 5 6 5 10 8 9 100 99 100
Sample Output 2
0
Sample Input 3
5 6 100 200 50 30 40 90 80 85 88 91 1 1 1 1 1000000000 50 100 51 49 48 3 3 3 3 7 10 10 10 10 20
Sample Output 3
4
Sample Input 4
10 8 5 3 2 1 1 1 1 1 1 1 100 100 50 40 30 20 10 5 3 1 1000 400 499 500 200 100 50 25 12 6 7 7 7 7 7 7 7 7 7 14 999999999 500000000 1 1 1 1 1 1 1 1 1000000000 500000000 499999999 1 1 1 1 1 1 1 12 6 6 6 6 6 6 6 6 6 50 26 25 24 23 22 21 20 19 18
Sample Output 4
4
Sample Input 5
2 1 2 1
Sample Output 5
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は、N 個の島が点在する広大な海域にいます。島には 1 から N までの番号が付けられており、島 i は二次元平面上の座標 (X_i, Y_i) に位置しています。
高橋君は小型ボートを使って島から島へと移動します。高橋君は現在いる島から、ユークリッド距離が D 以下である別の島へ一度に移動することができます。ここで、島 i と島 j のユークリッド距離は \sqrt{(X_i - X_j)^2 + (Y_i - Y_j)^2} で定義されます。なお、一度訪れた島を再び訪れることも許されます。
高橋君は島 S からスタートし、島 T にたどり着きたいと考えています。島 S から島 T まで移動するために必要な最小の移動回数を求めてください。たどり着くことが不可能な場合は -1 を出力してください。
制約
- 2 \leq N \leq 1500
- 1 \leq D \leq 10^9
- 1 \leq S \leq N
- 1 \leq T \leq N
- S \neq T
- -10^9 \leq X_i \leq 10^9
- -10^9 \leq Y_i \leq 10^9
- i \neq j ならば (X_i, Y_i) \neq (X_j, Y_j)
- 入力はすべて整数である
入力
N D S T X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
- 1 行目には、島の個数を表す N、一度に移動できる最大距離を表す D、出発する島の番号を表す S、目的の島の番号を表す T が、スペース区切りで与えられる。
- 続く N 行では、各島の座標が与えられる。
- このうち i 行目(1 \leq i \leq N)では、島 i の x 座標 X_i と y 座標 Y_i が、スペース区切りで与えられる。
出力
高橋君が島 S から島 T まで移動するために必要な最小の移動回数を 1 行で出力せよ。たどり着くことが不可能な場合は -1 を出力せよ。
入力例 1
5 3 1 5 0 0 2 1 -1 2 3 -1 4 3
出力例 1
2
入力例 2
4 2 1 4 0 0 1 1 2 0 100 100
出力例 2
-1
入力例 3
8 5 1 8 0 0 3 4 -2 3 1 -4 7 7 4 0 0 5 10 10
出力例 3
3
Score : 366 pts
Problem Statement
Takahashi is in a vast sea area dotted with N islands. The islands are numbered from 1 to N, and island i is located at coordinates (X_i, Y_i) on a two-dimensional plane.
Takahashi travels from island to island using a small boat. From his current island, he can move to another island in one step if the Euclidean distance between them is at most D. Here, the Euclidean distance between island i and island j is defined as \sqrt{(X_i - X_j)^2 + (Y_i - Y_j)^2}. Note that he is allowed to revisit islands he has already visited.
Takahashi starts at island S and wants to reach island T. Find the minimum number of moves required to travel from island S to island T. If it is impossible to reach island T, output -1.
Constraints
- 2 \leq N \leq 1500
- 1 \leq D \leq 10^9
- 1 \leq S \leq N
- 1 \leq T \leq N
- S \neq T
- -10^9 \leq X_i \leq 10^9
- -10^9 \leq Y_i \leq 10^9
- If i \neq j, then (X_i, Y_i) \neq (X_j, Y_j)
- All input values are integers
Input
N D S T X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
- The first line contains N representing the number of islands, D representing the maximum distance that can be traveled in one move, S representing the number of the starting island, and T representing the number of the destination island, separated by spaces.
- The following N lines give the coordinates of each island.
- The i-th of these lines (1 \leq i \leq N) contains the x-coordinate X_i and y-coordinate Y_i of island i, separated by a space.
Output
Output in one line the minimum number of moves required for Takahashi to travel from island S to island T. If it is impossible to reach island T, output -1.
Sample Input 1
5 3 1 5 0 0 2 1 -1 2 3 -1 4 3
Sample Output 1
2
Sample Input 2
4 2 1 4 0 0 1 1 2 0 100 100
Sample Output 2
-1
Sample Input 3
8 5 1 8 0 0 3 4 -2 3 1 -4 7 7 4 0 0 5 10 10
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は図書館の司書として、 N 日間にわたる蔵書点検を担当しています。
この図書館には M 冊の本があります。本の劣化や破損を見逃さないため、各本 j (1 \leq j \leq M) は N 日間のうち少なくとも R_j 日は点検しなければならないという基準が設けられています。
一方、 i 日目 (1 \leq i \leq N) に点検できる本の冊数は最大で L_i 冊です。また、同じ日に同じ本を複数回点検することはできませんが、異なる日であれば同じ本を再び点検することができます。
高橋君はどの日にどの本を点検するかを自由に決めることができます。うまく点検計画を立てることで、すべての本の点検基準を満たすことが可能かどうかを判定してください。
すなわち、以下の条件をすべて満たすような点検計画が存在するかどうかを判定してください。
- 各日 i に点検する本の冊数は L_i 冊以下である。
- 同じ日に同じ本を2回以上点検することはない。
- 各本 j が点検される日数の合計は R_j 日以上である。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq L_i \leq M (1 \leq i \leq N)
- 1 \leq R_j \leq N (1 \leq j \leq M)
- 入力はすべて整数
入力
N M L_1 L_2 \ldots L_N R_1 R_2 \ldots R_M
- 1 行目には、点検期間の日数を表す N と、本の冊数を表す M が、スペース区切りで与えられる。
- 2 行目には、各日に点検できる本の最大冊数を表す L_1, L_2, \ldots, L_N が、スペース区切りで与えられる。
- 3 行目には、各本の必要点検日数を表す R_1, R_2, \ldots, R_M が、スペース区切りで与えられる。
出力
すべての本の点検基準を満たすような点検計画が存在する場合は Yes を、存在しない場合は No を1行で出力せよ。
入力例 1
3 4 2 3 2 1 2 1 2
出力例 1
Yes
入力例 2
2 3 2 2 2 2 1
出力例 2
No
入力例 3
5 6 4 3 5 2 4 2 3 1 2 3 2
出力例 3
Yes
Score : 400 pts
Problem Statement
Takahashi is working as a librarian and is in charge of a book inspection spanning N days.
This library has M books. To ensure that no deterioration or damage to books is overlooked, a standard has been established that each book j (1 \leq j \leq M) must be inspected on at least R_j days out of the N days.
On the other hand, the maximum number of books that can be inspected on day i (1 \leq i \leq N) is L_i. Also, the same book cannot be inspected multiple times on the same day, but the same book can be inspected again on a different day.
Takahashi is free to decide which books to inspect on which days. Determine whether it is possible to create an inspection plan that satisfies the inspection requirements for all books.
Specifically, determine whether there exists an inspection plan that satisfies all of the following conditions:
- The number of books inspected on each day i is at most L_i.
- The same book is not inspected more than once on the same day.
- The total number of days each book j is inspected is at least R_j.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq L_i \leq M (1 \leq i \leq N)
- 1 \leq R_j \leq N (1 \leq j \leq M)
- All input values are integers
Input
N M L_1 L_2 \ldots L_N R_1 R_2 \ldots R_M
- The first line contains N, the number of days in the inspection period, and M, the number of books, separated by a space.
- The second line contains L_1, L_2, \ldots, L_N, the maximum number of books that can be inspected on each day, separated by spaces.
- The third line contains R_1, R_2, \ldots, R_M, the required number of inspection days for each book, separated by spaces.
Output
If an inspection plan that satisfies the inspection requirements for all books exists, print Yes; otherwise, print No on a single line.
Sample Input 1
3 4 2 3 2 1 2 1 2
Sample Output 1
Yes
Sample Input 2
2 3 2 2 2 2 1
Sample Output 2
No
Sample Input 3
5 6 4 3 5 2 4 2 3 1 2 3 2
Sample Output 3
Yes
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