0% found this document useful (0 votes)
23 views

Setcover (En)

Alice has an array of sets that was modified by Farhan. She wants to select the minimum number of sets from the modified array such that their union contains all elements from 1 to k. The input specifies the modified array B, and the output must identify the minimum number of sets and their indices. Solving this set cover problem optimally finds the smallest collection of sets whose elements collectively contain all other elements.

Uploaded by

mohammodhasan396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Setcover (En)

Alice has an array of sets that was modified by Farhan. She wants to select the minimum number of sets from the modified array such that their union contains all elements from 1 to k. The input specifies the modified array B, and the output must identify the minimum number of sets and their indices. Solving this set cover problem optimally finds the smallest collection of sets whose elements collectively contain all other elements.

Uploaded by

mohammodhasan396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Bangladesh Olympiad in Informatics setcover

National Round Day 2 T asks


28-29 April, 2023 English

Interval Set Cover


Alice has an array of n empty sets: A[1], A[2], … , A[n]. Since the empty sets are not interesting,
she wants to perform k operations on them. On operation i, Alice selects two integers l[i] and r[i]
such that 1 ≤ l[i] ≤ r[i] ≤ n, and adds the element i to all sets A[j] such that l[i] ≤ j ≤ r[i].

For example, if n = 3 and k = 2 , and Alice picks (l[1], r[1]) = (2, 3) and (l[2], r[2]) = (1, 3) ,
then, after the first operation,

A[1] = {} , A[2] = {1} , and A[3] = {1} ,

and after the second operation,

A[1] = {2} , A[2] = {1, 2} , and A[3] = {1, 2} .

After all k operations are done, Alice’s sets have a really cool structure. However, Farhan is jealous of
this, so he concocts an wicked plan:

First, he chooses a permutation p = (p 1 , p 2 , … , p n ) of the integers 1, 2, … , n; that is, p has


​ ​ ​

each of the numbers from 1 to n exactly once in some order of Farhan’s choosing.
Then he creates another array B of sets B[1], B[2], … , B[n] such that B[i] = A[p i ]. ​

Finally, he masterfully replaces Alice’s array A with his new array B when she is not around.

Alice, of course, notices that her array of sets has been messed around. Unfortunately, she no longer
remembers the integers l[i] and r[i]. It makes Alice sad, so she wants to keep some of sets from the
new array and throw the rest of them away. But she wants to do it in a such that every element from 1
to k is in at least of one the sets that she keeps.

More formally, Alice wants to select the minimum number of sets such that their union is
{1, 2, … , k} .

Input
You will be given the array of sets B in the input. Let’s assume that the set B[i] has ci unique ​

elements. Let those elements be B[i][1], B[i][2], … , B[i][ci ] without duplication.


Read the input from the standard input in the following format:

line 1 : n k
line 2i (1 ≤ i ≤ n): ci ​

line 2i + 1 (1 ≤ i ≤ n): B[i][1] B[i][2] … B[i][ci ] ​

setcover (1 of 3)
Output
Suppose the minimum number of sets Alice has to keep is m , and the m sets she chooses are
B[t1 ], B[t2 ], … , B[tm ]. Write the output to the standard output in the following format:
​ ​ ​

line 1 : m
line 2 : t1 t2 … tm
​ ​ ​

You can output the indices in any order. If there are multiple solutions, you may print any of them.

Constraints
1 ≤ n ≤ 2000
1 ≤ k ≤ 2000
1 ≤ ti ≤ k (for all 1 ≤ i ≤ n)
1 ≤ B[i][j] ≤ k (for all 1 ≤ i ≤ n and 1 ≤ j ≤ ti ) ​

For each integer j such that 1 ≤ j ≤ k , there is at least one set which contains j .

Subtasks
1. (4 points) n ≤ 15
2. (5 points) k ≤ 15
3. (11 points) p i = i (for all 1 ≤ i ≤ n)

4. (17 points) n, k ≤ 80 , and for any two i, j (1 ≤ i, j ≤ k ), the ranges [l[i], r[i]] and [l[j], r[j]]
must either be disjoint, or one must be contained by another.
5. (20 points) n, k ≤ 80
6. (15 points) n, k ≤ 300
7. (28 points) No further constraints.

Example 1

3 2
2
1 2
1
2
2
1 2‎

The correct output is:

1
1‎

setcover (2 of 3)
This example is described in the problem statement. Notice that p = (2, 1, 3) . The optimal solution
chooses the set B[1] which includes all elements. Choosing the set B[3] is also a valid solution.

Example 2

3 5
2
1 2
2
2 3
3
1 4 5‎

The correct output is:

2
2 3‎

Here, it’s optimal to keep sets B[2] and B[3], which covers all 5 elements. It’s easy to see that there
cannot be any solution that includes only one set, hence this is optimal.

setcover (3 of 3)

You might also like