#P9557. [SDCPC 2023] Building Company
[SDCPC 2023] 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.
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.
