This problem is precisely equivalent to the Vertex Cover problem on a bipartite graph, with a vertex on one side for each first-name initial, and a vertex on the other side for each last-name initial. Each person is an edge from the "first name" vertex to the "second name" vertex.

While vertex cover is NP-hard in general, it turns out to be polynomially solvable on a bipartite graph. Konig's theorem says the minimal vertex cover size is equal to the maximum matching size (and the matching can be found by standard max flow).

However, this problem is also solvable by enumeration. If we correctly guess the set of last-name initials that groups are formed around, then it is clear how many first-name groups are needed to complete the partition (by looking at the first names for all people whose last initial was not chosen). There are 2^18 = 262,144 choices for the last-name groups, so we can afford to try them all.

The remainder of this file provides solutions, and proof of optimality, for the judge's data sets.