#P14575. 坤班
坤班
Description
Legendary Face Middle School is now recruiting students!
There are teachers in the school, and they need to teach subjects. Each teacher can use a triple to indicate that he teaches , and can teach at most classes. If , it means that teacher is unwilling to be a class teacher, otherwise it means that he is willing to be a class teacher.
In particular, because being a class teacher will consume a lot of energy, if a teacher chooses to be a class teacher, he can only teach at most classes.
Of course, each class must have a class teacher, and each subject must have a teacher. It should be noted that a class teacher does not necessarily have to be the subject teacher of the class he or she is assigned to.
The school hopes to form more classes to recruit more outstanding OIers. The admissions team specially invites you, as a Legendary Grandmaster, to help calculate the maximum number of classes that can be formed.
Input Format
The first line reads two positive integers , which represent the number of teachers and the number of subjects in Legendary Face Middle School.
Next , each line contains three integers , as described in the question.
Output Format
The output is one line, indicating the maximum number of classes that can be formed in Legendary Face Middle School.
5 2
1 2 1
1 2 1
1 1 0
2 2 1
2 2 1
3
Hint
Sample Explanation
Teachers numbered are homeroom teachers for three classes, respectively.
Teachers numbered teach Subject 1 to three classes, respectively.
Teacher numbered teaches Subject 2 to one class, and teacher numbered teaches Subject 3 to two classes.
Data range
| Subtask | Special Properties | Score | |
|---|---|---|---|
| Subtask 1 | A | ||
| Subtask 2 | None | ||
| Subtask 3 | B | ||
| Subtask 4 | None | ||
| Subtask 5 | B | ||
| Subtask 6 | None |
- Special property A: Satisfy .
- Special property B: .
For of the data:
- .
- , , , .
京公网安备 11011102002149号