P28651 [洛谷] [APIO2007] The Animal Park
提高+
题目描述

Problem Description

The newly built circular animal park is a source of pride for the Asia-Pacific region. Situated on a small island in the Pacific, the park consists of a large circular enclosure, with each section housing a different species of animal.

As the public director of the park, your goal is to ensure that every visitor enjoys their time as much as possible. Today, a group of children is visiting the park, and you want to make their experience delightful. However, this is not an easy task—some animals are liked by certain children, while others are feared. For example, Alex loves cute monkeys and koalas but is afraid of lions with sharp teeth. Polly, on the other hand, admires lions for their beautiful manes but is repelled by the smell of koalas. You can choose to remove some animals from their enclosures to prevent children from being scared, but you cannot remove too many, or there will be nothing left for the children to see. Each child stands outside the circular enclosure and can see five consecutive sections. You have been provided with information about which animals each child likes and fears. A child will be happy if either of the following conditions is met:
- At least one of the animals they fear is removed.
- At least one of the animals they like is not removed.

For example, consider the following scenario:

  • If you remove the animals from sections 4 and 12, Alex and Ka-Shu will be happy because at least one of their feared animals is gone. This will also make Chaitanya happy as he can still see the animals he likes in sections 6 and 8. However, Polly and Hwan will be unhappy as they cannot see any of the animals they like, and all the animals they fear are still there. This arrangement makes three children happy.
  • If you instead remove the animals from sections 4 and 6, Alex and Polly will be happy because their feared animals are gone. Chaitanya will also be happy as he can still see the animal he likes in section 8. Hwan will be happy too, as he can see the animal he likes in section 12. Only Ka-Shu will be unhappy.
  • If you only remove the animal from section 13, Ka-Shu will be happy because one of his feared animals is gone, and Alex, Polly, Chaitanya, and Hwan will also be happy as they can see at least one of the animals they like. This method makes the maximum number of children happy.

Input Format

The first line of input contains two integers, $N$ and $C$, separated by a space.

$N$ is the number of sections (enclosures) ($10 \le N \le 10^4$), and $C$ is the number of children ($1 \le C \le 5 \times 10^4$).

The sections are numbered clockwise from 1 to $N$.

The next $C$ lines describe the information for each child in the following format: $E, F, L, X_1, X_2, \cdots, X_F, Y_1, Y_2, \cdots, Y_L$.

Where:
- $E$ is the number of the first section the child can see ($1 \le E \le N$), meaning the child can see sections $E, E+1, E+2, E+3, E+4$.
- If the number exceeds $N$, it wraps around to 1.
- $F$ is the number of animals the child fears.
- $L$ is the number of animals the child likes.
- Sections $X_1, X_2, \cdots, X_F$ contain the animals the child fears.
- Sections $Y_1, Y_2, \cdots, Y_L$ contain the animals the child likes.
- $X_1, X_2, \cdots, X_F, Y_1, Y_2, \cdots, Y_L$ are distinct integers, and the sections they represent are all within the child's view.

The children are sorted by the number of the first section they can see, with the smallest $E$ first and the largest $E$ last. Note that multiple children may have the same $E$.

Output Format

Output a single number, which is the maximum number of children that can be made happy.

Sample Input and Output

Input Sample #1

14 5 
2 1 2 4 2 6 
3 1 1 6 4 
6 1 2 9 6 8
8 1 1 9 12 
12 3 0 12 13 2 

Output Sample #1

5

Input Sample #2

12 7 
1 1 1 1 5 
5 1 1 5 7 
5 0 3 5 7 9 
7 1 1 7 9 
9 1 1 9 11 
9 3 0 9 11 1
11 1 1 11 1

Output Sample #2

6

Notes/Hints

Data Range
For $100\%$ of the data, $10 \le N \le 10^4$, $1 \le C \le 5 \times 10^4$, $1 \le E \le N$.

Sample Explanation
- The first sample is the example described in the problem, where all $C=5$ children can be made happy.
- The second sample is an example where not all $C=7$ children can be made happy.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
14 5 2 1 2 4 2 6 3 1 1 6 4 6 1 2 9 6 8 8 1 1 9 12 12 3 0 12 13 2
样例输出
5