CF1466F.Euclid's nightmare

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.

In his bad dream Euclid has a set SS of nn mm-dimensional vectors over the Z2\mathbb{Z}_2 field and can perform vector addition on them. In other words he has vectors with mm coordinates, each one equal either 00 or 11. Vector addition is defined as follows: let u+v=wu+v = w, then wi=(ui+vi) mod 2w_i = (u_i + v_i) \bmod 2.

Euclid can sum any subset of SS and archive another mm-dimensional vector over Z2\mathbb{Z}_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 00.

Let TT be the set of all the vectors that can be written as a sum of some vectors from SS. Now Euclid wonders the size of TT and whether he can use only a subset S′S' of SS to obtain all the vectors from TT. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in SS have at most 22 coordinates equal 11.

Help Euclid and calculate ∣T∣|T|, the number of mm-dimensional vectors over Z2\mathbb{Z}_2 that can be written as a sum of some vectors from SS. As it can be quite large, calculate it modulo 109+710^9+7. You should also find S′S', the smallest such subset of SS, that all vectors in TT can be written as a sum of vectors from S′S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.

Consider sets AA and BB such that ∣A∣=∣B∣|A| = |B|. Let a1,a2,…a∣A∣a_1, a_2, \dots a_{|A|} and b1,b2,…b∣B∣b_1, b_2, \dots b_{|B|} be increasing arrays of indices elements of AA and BB correspondingly. AA is lexicographically smaller than BB iff there exists such ii that aj=bja_j = b_j for all j<ij \lt i and ai<bia_i \lt b_i.

你可能知道欧几里得是一位数学家。事实上,墨菲斯也知道这一点。因此,当他想对欧几里得施加一个恶作剧时,便给他安排了一场恰如其分的噩梦。

在噩梦中,欧几里得拥有一个由 nn 个 mm 维向量构成的集合 SS,这些向量定义在 Z2\mathbb{Z}_2 域上,并可在其上进行向量加法运算。换言之,这些向量具有 mm 个坐标,每个坐标值非 00 即 11。向量加法定义如下:设 u+v=wu+v = w,则 wi=(ui+vi) mod 2w_i = (u_i + v_i) \bmod 2。

欧几里得可以对 SS 的任意子集求和,从而得到另一个 mm 维 Z2\mathbb{Z}_2 向量。特别地,他也可以对空子集求和;此时所得向量的所有坐标均为 00。

令 TT 表示所有可表示为 SS 中某些向量之和的向量所构成的集合。现在欧几里得想知道 TT 的大小 ∣T∣|T|,以及是否能仅用 SS 的某个子集 S′S' 就生成 TT 中全部向量。正如这类情形中通常发生的那样,他只有彻底弄清这个问题后才能醒来。目前,这位哲学家的处境看起来相当不妙。但尚存一线希望——他注意到 SS 中所有向量至多有 22 个坐标等于 11。

请帮助欧几里得计算 ∣T∣|T|,即所有可表示为 SS 中某些向量之和的 mm 维 Z2\mathbb{Z}_2 向量的个数。由于该值可能非常大,请对 109+710^9+7 取模输出。你还需找出 S′S',即满足“利用 S′S' 中向量的和即可生成 TT 中所有向量”的最小(元素个数最少)子集 S′⊆SS' \subseteq S。若存在多个满足最小元素个数的子集,则输出其中按输入顺序下标字典序最小的那个。

考虑两个集合 AA 和 BB,且 ∣A∣=∣B∣|A| = |B|。设 a1,a2,…,a∣A∣a_1, a_2, \dots, a_{|A|} 和 b1,b2,…,b∣B∣b_1, b_2, \dots, b_{|B|} 分别为 AA 和 BB 中元素在输入中下标的升序排列数组。称 AA 字典序小于 BB,当且仅当存在某个 ii,使得对所有 j<ij < i 都有 aj=bja_j = b_j,且 ai<bia_i < b_i。

输入格式

In the first line of input, there are two integers nn, mm (1≤n,m≤5⋅1051 \leq n, m \leq 5 \cdot 10^5) denoting the number of vectors in SS and the number of dimensions.

Next nn lines contain the description of the vectors in SS. In each of them there is an integer kk (1≤k≤21 \leq k \leq 2) and then follow kk distinct integers x1,…xkx_1, \dots x_k (1≤xi≤m1 \leq x_i \leq m). This encodes an mm-dimensional vector having 11s on coordinates x1,…xkx_1, \dots x_k and 00s on the rest of them.

Among the nn vectors, no two are the same.

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤5⋅1051 \leq n, m \leq 5 \cdot 10^5),分别表示集合 SS 中向量的个数以及向量的维数。

接下来的 nn 行描述集合 SS 中的向量。每行首先是一个整数 kk(1≤k≤21 \leq k \leq 2),随后是 kk 个互不相同的整数 x1,…,xkx_1, \dots, x_k(1≤xi≤m1 \leq x_i \leq m)。这表示一个 mm 维向量,其在坐标 x1,…,xkx_1, \dots, x_k 处取值为 11,其余坐标处取值为 00。

在全部 nn 个向量中,任意两个向量均不相同。

输出格式

In the first line, output two integers: remainder modulo 109+710^9+7 of ∣T∣|T| and ∣S′∣|S'|. In the second line, output ∣S′∣|S'| numbers, indices of the elements of S′S' in ascending order. The elements of SS are numbered from 11 in the order they are given in the input.

第一行输出两个整数:∣T∣|T| 对 109+710^9+7 取模的余数,以及 ∣S′∣|S'|。
第二行输出 ∣S′∣|S'| 个数字,表示 S′S' 中各元素在 SS 中的下标(按升序排列)。SS 中的元素从 11 开始编号,编号顺序与输入中给出的顺序一致。

输入输出样例

  • 输入#1

    3 2
    1 1
    1 2
    2 2 1

    输出#1

    4 2
    1 2
  • 输入#2

    2 3
    2 1 3
    2 1 2

    输出#2

    4 2
    1 2
  • 输入#3

    3 5
    2 1 2
    1 3
    1 4

    输出#3

    8 3
    1 2 3

说明/提示

In the first example we are given three vectors:

  • 1010
  • 0101
  • 1111

It turns out that we can represent all vectors from our 22-dimensional space using these vectors:

  • 0000 is a sum of the empty subset of above vectors;
  • 01=11+1001 = 11 + 10, is a sum of the first and third vector;
  • 10=1010 = 10, is just the first vector;
  • 11=10+0111 = 10 + 01, is a sum of the first and the second vector.

Hence, T=00,01,10,11T = {00, 01, 10, 11}. We can choose any two of the three vectors from SS and still be able to obtain all the vectors in TT. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in TT using only a single vector from SS, ∣S′∣=2|S'| = 2 and S′=10,01S' = {10, 01} (indices 11 and 22), as set 1,2{1, 2 } is lexicographically the smallest. We can represent all vectors from TT, using only vectors from S′S', as shown below:

  • 0000 is a sum of the empty subset;
  • 01=0101 = 01 is just the second vector;
  • 10=1010 = 10 is just the first vector;
  • 11=10+0111 = 10 + 01 is a sum of the first and the second vector.

在第一个例子中,我们给出了三个向量:

  • 1010
  • 0101
  • 1111

事实上,我们可以利用这三个向量表示二维空间中的所有向量:

  • 0000 是上述向量的空子集的和;
  • 01=11+1001 = 11 + 10,是第一个与第三个向量的和;
  • 10=1010 = 10,即第一个向量本身;
  • 11=10+0111 = 10 + 01,是第一个与第二个向量的和。

因此,T={00,01,10,11}T = \{00, 01, 10, 11\}。我们可以从 SS 中任选其中两个向量,仍能生成 TT 中的所有向量。此时,我们选择输入中出现顺序最靠前的两个向量。由于仅用 SS 中的一个向量无法生成 TT 中的所有向量,故 ∣S′∣=2|S'| = 2,且 S′={10,01}S' = \{10, 01\}(对应下标 11 和 22),因为集合 {1,2}\{1, 2\} 是字典序最小的。我们仅使用 S′S' 中的向量即可表示 TT 中的所有向量,如下所示:

  • 0000 是空子集的和;
  • 01=0101 = 01 即第二个向量本身;
  • 10=1010 = 10 即第一个向量本身;
  • 11=10+0111 = 10 + 01 是第一个与第二个向量的和。

输入解题思路,AI测评打分。不知道怎么写?

首页