#### CodeForces Contest > 1761 Problem C (Set Construction) – How to solve this problem?

Guys I have been working on this problem since morning (4 hours ago) and still couldn’t find a proper answer. Can anyone help me?

• Problem Explanation:
The problem “Set Construction” from Codeforces requires constructing sets based on a given binary matrix, with certain rules for inclusion and comparison. Let’s break it down:

### Problem Explanation

1. Input:

• You have a binary matrix `b` with dimensions `n x n`, where each element is either 0 or 1.
2. Output:

• You need to construct `n` sets ( A_1, A_2, dots, A_n ) consisting of distinct integers from 1 to ( n ).
3. Conditions:

• Each set must be non-empty and distinct.
• The matrix `b` indicates the subset relationship between these sets:
• If `b[i][j] = 1`, then the set ( A_i ) must be a proper subset of ( A_j ).
• If `b[i][j] = 0`, then the set ( A_i ) must not be a subset of ( A_j ).
4. Proper Subset:

• A set ( A_i ) is a proper subset of ( A_j ) if all elements of ( A_i ) are in ( A_j ), and ( A_i ) is strictly smaller (i.e., ( A_i neq A_j )).

### Construction of Sets

To create the sets:

1. Start with each set containing its index: ( A_i = {i+1} ).
2. For each 1 in the matrix `b[i][j]`, add the elements of ( A_i ) to ( A_j ).

### Example

For instance, if the matrix `b` is:

``````0 1 0
0 0 1
0 0 0
``````
• It indicates ( A_1 ) should be a proper subset of ( A_2 ), and ( A_2 ) should be a proper subset of ( A_3 ). Thus, you might have:
• ( A_1 = {1} )
• ( A_2 = {1, 2} )
• ( A_3 = {1, 2, 3} )

This ensures the proper subset relationships as indicated by the matrix `b`.

### Implementation Notes

The solution involves iterating over the matrix and ensuring that the sets are constructed according to the proper subset relationships. For each 1 in the matrix, the corresponding set relationships are established. If a zero is encountered, the corresponding sets must not have a subset relationship.

Example:

``````- Input
2
4
0001
1001
0001
0000
3
011
001

- Output
3 1 2 3
2 1 3
2 2 4
4 1 2 3 4
1 1
2 1 2
3 1 2 3
``````
• My C# code is here:
``````int t = int.Parse(Console.ReadLine());

for (int i = 0; i < t; i++)
{
int[,] b = new int[n, n]; // nxn size, 2d array def

for (int j = 0; j < n; j++)
{
for (int k = 0; k < n; k++)
{
}
}

List<HashSet<int>> sets = new List<HashSet<int>>();

for (int j = 0; j < n; j++)
{
HashSet<int> set = new HashSet<int>();

for (int k = 0; k < n; k++)
{
if(b[j, k] == 1) {
set.Remove(j+1);
}

}