#P4835. [JSOI2014] 学生选课
[JSOI2014] 学生选课
Description
After entering university, students need to choose courses. There are students who need to choose courses, and there are three teachers in the school: JYY, YJY, and YYJ.
In the first year, each student chose one of the teachers. After a year of study, students have formed some impressions of each other. Each student ranks the other students from best to worst based on their impressions. The second-year course selection begins. Each student needs to choose a teacher, and perhaps because they have been “tricked” too many times, every student wants to switch to a different teacher. You need to schedule the students' course selections so that, among students taking the same class, the worst mutual impression is as good as possible.
Input Format
The first line contains an integer .
The next lines each contain positive integers. Line provides the information of student . The first integer is , which is one of , representing the teacher chosen by student in the first year. The next numbers are a permutation of , representing student 's ranking of the other students from best to worst.
Output Format
Output one integer: the smallest non-negative integer such that:
- Every student chooses a different teacher from the one they chose in the first year.
- For any two students who choose the same teacher, their impressions of each other are both within the top .
6
0 2 3 4 5 6
0 1 3 4 5 6
1 6 5 4 2 1
2 6 5 3 2 1
1 1 2 3 4 6
2 1 2 3 4 5
4
Hint
Sample Explanation 1
The six students chose teachers , respectively.
At this time, in teacher 's class, student ranks student as the -th best, so the answer is , and there is no smaller .
Constraints
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号