Infiltration
Time limit10sMemory limit128 MB
In a tournament digraph, find the smallest set of vertices whose closed out-neighborhoods cover all vertices, and output the lexicographically smallest such set.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Implementation, Brute force
- Solved
- No attempts yet
Problem
An organization's command structure is divided into several cells. For every pair of distinct cells and , exactly one of the following holds: controls , or controls . This "controls" relation may be cyclic, so it can happen that controls , controls , and controls .
You may infiltrate any single cell. Infiltrating a cell gives you control over that cell together with every cell it controls, and no others. In the cyclic example above, infiltrating gives control over and (the cell controls), but not .
A successful operation requires control over every cell; any cell left out of your control would expose the operation. Because resources are tight, the operation must be as efficient as possible. Determine the minimum number of cells that must be infiltrated so that the infiltrated cells, together with the cells they control, cover all cells.
Input
The input consists of one or more test cases and continues until end of file.
The first line of each test case contains the number of cells (). Each of the next lines contains a binary string of length ; the -th character of the -th line is if cell controls cell , and otherwise ().
The -th character of the -th line is , and for exactly one of the -th character of the -th line and the -th character of the -th line is (never both).
Output
For each test case, output one line in the format Case X: m c1 c2 ... cm, where X is the test case number (starting from ) and m is the minimum number of cells that must be infiltrated to obtain complete control of all cells. After m, list the cell numbers of one such minimum set as c1 c2 ... cm in strictly increasing order. When more than one minimum set exists, output the lexicographically smallest one — the set whose increasing sequence of cell numbers is smallest in lexicographic order.