#P4929. Unique Column Coverage in Binary Matrix

    ID: 18170 Type: Default 1000ms 256MiB

Unique Column Coverage in Binary Matrix

Unique Column Coverage in Binary Matrix

You are given a binary matrix of size \(N \times M\) where each element is either \(0\) or \(1\). Your task is to select a subset of rows such that for every column \(j\) (\(1 \leq j \leq M\)), the sum of the selected rows in that column is exactly \(1\). In other words, if you denote the selected set of rows by \(S\), then for each column \(j\), we require that

[ \sum_{i \in S} a_{ij} = 1 ]

If such a selection exists, output YES and a valid set of row indices. Otherwise, output NO.

Note: The row indices are considered to be 1-indexed.

inputFormat

The first line contains two integers \(N\) and \(M\) representing the number of rows and columns of the matrix respectively. The following \(N\) lines each contain \(M\) space-separated integers (either 0 or 1) representing the rows of the matrix.

N M
row1_element1 row1_element2 ... row1_elementM
row2_element1 row2_element2 ... row2_elementM
...
rowN_element1 rowN_element2 ... rowN_elementM

outputFormat

If a valid subset of rows exists, output YES on the first line. On the second line, print an integer \(K\) denoting the number of selected rows. On the third line, print \(K\) space-separated integers representing the 1-indexed row numbers of your chosen subset (in any order). If there is no valid selection, output NO.

sample

3 3
1 0 0
0 1 1
0 1 0
YES

2 1 2

</p>