luogu#P9557. [SDCPC2023] Building Company
[SDCPC2023] Building Company
题目描述
You're the boss of a building company. At the beginning, there are types of employees in the company, and different types of employees have different occupations. For the -th type of employees, their occupation can be numbered as and there are employees in total.
There are building projects in the market waiting to be undertaken. To undertake the -th project, your company must meet requirements. The -th requirement requires that your company has at least employees whose occupation is . After undertaking the project, your company will become more famous and will attract types of employees to join your company. The occupation of the -th type of employees is and there are employees in total.
You can undertake any number of projects in any order. Each project can be undertaken at most once. Calculate the maximum number of projects you can undertake.
Note that employees are not consumables. After undertaking a project the number of employees in your company won't decrease.
输入格式
There is only one test case in each test file.
The first line of the input first contains an integer () indicating the number of types of employees in the company at the beginning. Then pairs of integers follow (), where and indicate that there are employees whose occupation is . It's guaranteed that for all we have .
The second line contains an integer () indicating the number of projects waiting to be undertaken.
For the following lines, each two lines describe a project.
The -th line first contains an integer () indicating the number of requirements to undertake the -th project. Then pairs of integers $a_{i, 1}, b_{i, 1}, a_{i, 2}, b_{i, 2}, \cdots, a_{i, m_i}, b_{i, m_i}$ follow () where and indicate that the company is required to have at least employees whose occupation is . It's guaranteed that for all we have .
The -th line first contains an integer () indicating the number of types of employees to join the company after undertaking the -th project. Then pairs of integers $c_{i, 1}, d_{i, 1}, c_{i, 2}, d_{i, 2}, \cdots, c_{i, k_i}, d_{i, k_i}$ follow () where and indicate that there are employees whose occupation is joining the company. It's guaranteed that for all we have .
It's guaranteed that neither the sum of nor the sum of will exceed .
输出格式
Output one line containing one integer indicating the maximum number of projects you can undertake.
题目大意
【题目描述】
您是一家建筑公司的老板。一开始,公司共有 类员工,每一类员工都属于一个工种。第 类员工的工种编号为 ,共有 人。
市场上共有 项工程等待承接。想要承接第 项工程,您的公司需要满足 项要求,其中第 项要求您的公司至少有工种编号为 的员工 人。承接该工程后,您的公司将会更加有名,并吸引 类员工加入公司,其中第 类员工的工种编号为 ,共有 人。
您可以按任意顺序承接任意数量的工程,每项工程最多只能被承接一次。求最多能承接多少工程。
请注意:员工不是消耗品。承接一项工程后,员工的数量不会减少。
【输入格式】
每个测试文件仅有一组测试数据。
第一行首先输入一个整数 ()表示一开始公司内员工的种类数。接下来输入 对整数 (),其中 和 表示一开始工种编号为 的员工共有 人。保证对于所有 有 。
第二行输入一个整数 ()表示等待承接的工程数量。
对于接下来 行,每两行描述一项工程。
第 行首先输入一个整数 ()表示承接第 项工程有几项要求。接下来输入 对整数 $a_{i, 1}, b_{i, 1}, a_{i, 2}, b_{i, 2}, \cdots, a_{i, m_i}, b_{i, m_i}$(),其中 和 表示公司至少要有工种编号为 的员工 人。保证对于所有 有 。
第 行首先输入一个整数 ()表示承接第 项工程之后有几类员工加入公司。接下来输入 对整数 $c_{i, 1}, d_{i, 1}, c_{i, 2}, d_{i, 2}, \cdots, c_{i, k_i}, d_{i, k_i}$(),其中 和 表示工种编号为 的员工共 人加入公司。保证对于所有 有 。
保证 与 之和均不超过 。
【输出格式】
输出一行一个整数表示最多能承接几项工程。
【样例解释】
样例解释如下,用 表示工种为 的员工有 名。
首先承接没有任何要求的第 项工程,承接后工种为 的 名员工加入公司。公司内现有员工为 。
接下来承接第 项工程,承接后没有员工加入公司。公司内现有员工仍为 。
接下来承接第 项工程,承接后工种为 的 名员工,以及工种为 的 名员工加入公司。公司内现有员工为 。
接下来承接第 项工程,承接后工种为 的 名员工加入公司。公司内现有员工为 。
由于工种为 的员工不足 名,因此无法承接仅剩的第 项工程。
2 2 1 1 2
5
1 3 1
0
2 1 1 2 1
2 3 2 2 1
3 1 5 2 3 3 4
1 2 5
3 2 1 1 1 3 4
1 1 3
0
1 3 2
4
提示
We explain the sample test case as follows. Let indicate employees whose occupation is .
First, undertake the -th project with no requirements. After undertaking the project, there are employees, whose occupation is , joining the company. The company now have these employees: .
Next, undertake the -st project. After undertaking the project, no employee joins the company. The company now still have these employees: .
Next, undertake the -nd project. After undertaking the project, there are employees, whose occupation is , and employee, whose occupation is , joining the company. The company now have these employees: .
Next, undertake the -th project. After undertaking the project, there are employees, whose occupation is , joining the company. The company now have these employees: .
As the company does not have employees whose occupation is , we cannot undertake the -rd project.