Under construction

Still being built. Things may change

Infiltration

Time limit10sMemory limit128 MB

Summary
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 AA and BB, exactly one of the following holds: AA controls BB, or BB controls AA. This "controls" relation may be cyclic, so it can happen that AA controls BB, BB controls CC, and CC controls AA.

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 AA gives control over AA and BB (the cell AA controls), but not CC.

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 nn of cells (1≤n≤751 \le n \le 75). Each of the next nn lines contains a binary string of length nn; the ii-th character of the jj-th line is 11 if cell jj controls cell ii, and 00 otherwise (1≤i,j≤n1 \le i, j \le n).

The ii-th character of the ii-th line is 00, and for i≠ji \ne j exactly one of the ii-th character of the jj-th line and the jj-th character of the ii-th line is 11 (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 11) 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.

Examples3

  1. Example 1

    Input
    2
    00
    10
    3
    010
    001
    100
    5
    01000
    00011
    11001
    10100
    10010
    
    Expected output
    Case 1: 1 2
    Case 2: 2 1 2
    Case 3: 2 2 3
    
  2. Example 2

    Input
    1
    0
    
    Expected output
    Case 1: 1 1
    
  3. Example 3

    Input
    4
    0111
    0011
    0001
    0000
    
    Expected output
    Case 1: 1 1