### James S. Plank

Fri Apr 8 11:07:04 EDT 2016
Problem Statement.
This is a straightforward set problem.

Your approach is, for each element i, to determine the size of the good subset that contains i. You then return the minimum size subset over all elements.

Now, I did this using two sets: visited and to_visit. You start by inserting element i in to_visit. Then you go through the following loop:

• While to_visit isn't empty:
• Remove an element j from to_visit.
• Add that element to visited.
• For every element k in visited, do the following:
• If table[j][k] is not in visited, and table[j][k] is not in to_visit, then add table[j][k] to to_visit.
• Do the same thing go table[k][j].
• I understand that table is not a two-dimensional array, but you should understand how to map my description to the actual problem.
• When to_visit is empty, the size of visited is the size of the good subset that contains element i.
This should run in roughly O(n3log(n)) time, which, for n capped at 50, is easily within topcoder's limits.