Problem A - Nordic Collegiate Programming Contest
Problem A - Nordic Collegiate Programming Contest
Problem A - Nordic Collegiate Programming Contest
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
NCPC 2012<br />
<strong>Problem</strong> K<br />
Kindergarten<br />
<strong>Problem</strong> ID: kindergarten<br />
Every year the three friendly teachers at the kindergarten let<br />
their classes’ kids change classes to form three new ones. Some<br />
kids, of course, are old enough to leave, but those who stay for<br />
another year are rearranged among the three teachers.<br />
The teachers even let the kids have their say in the process. As<br />
friendship both comes and goes hastily in young years, each kid X<br />
ranks every other kid Y according to how glad X would be to have<br />
Y in her new class. In fact, X produces a preference list giving a<br />
total order of the other kids, i.e. there are no such things as ties –<br />
kids she would be equally glad to have as class mates.<br />
The three teachers do not mind if the new classes formed are<br />
Photo by Lars Plougmann<br />
unbalanced in size, since they fill up their classes with new kids<br />
about to start their first year at the kindergarten. They do, however, want all the kids in their own new class to be<br />
different from last year, since even a teacher needs a break after a whole year with the same kids. They decide that<br />
a best partition into three classes under these premises is one where no kid is in the same class as a kid not listed<br />
among the top T entries on their preference list, for T as small as possible. Note that the kids in a new class may<br />
very well be the same as in an old one, but then with a new teacher!<br />
Input<br />
The first line of input contains a positive integer n ≤ 200 giving the number of kids to be rearranged at the<br />
kindergarden. The kids are numbered 1 through n.<br />
Then follow n lines describing the kids. The i-th row first contains the identifier of their current class’ teacher (an<br />
integer 0, 1, or 2), and next the n − 1 integers {1, 2, 3, . . . , i − 1, i + 1, . . . , n} in some order, describing the class<br />
mate preference list of the i-th kid, in descending order.<br />
Output<br />
The smallest non-negative integer T , such that there is a partitioning of the kids in three new classes such that<br />
• No kid has the same teacher as in their current class, and<br />
• all kids’ class mates are among the top T places of their preference lists, respectively.<br />
Sample Input 1 Sample Output 1<br />
6<br />
0 2 3 4 5 6<br />
0 1 3 4 5 6<br />
1 6 5 4 2 1<br />
2 6 5 3 2 1<br />
1 1 2 3 4 6<br />
2 1 2 3 4 5<br />
Sample Input 2 Sample Output 2<br />
3<br />
0 2 3<br />
1 1 3<br />
2 1 2<br />
4<br />
0<br />
NCPC 2012 <strong>Problem</strong> K: Kindergarten 21