CF704C.Black Widow

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Natalia Romanova is trying to test something on the new gun S.H.I.E.L.D gave her. In order to determine the result of the test, she needs to find the number of answers to a certain equation. The equation is of form:

Where represents logical OR and represents logical exclusive OR (XOR), and v__i, j are some boolean variables or their negations. Natalia calls the left side of the equation a XNF formula. Each statement in brackets is called a clause, and v__i, j are called literals.

In the equation Natalia has, the left side is actually a 2-XNF-2 containing variables _x_1, _x_2, ..., x__m and their negations. An XNF formula is 2-XNF-2 if:

  1. For each 1 ≤ i ≤ n, k__i ≤ 2, i.e. the size of each clause doesn't exceed two.
  2. Each variable occurs in the formula at most two times (with negation and without negation in total). Please note that it's possible that a variable occurs twice but its negation doesn't occur in any clause (or vice versa).

Natalia is given a formula of m variables, consisting of n clauses. Please, make sure to check the samples in order to properly understand how the formula looks like.

Natalia is more into fight than theory, so she asked you to tell her the number of answers to this equation. More precisely, you need to find the number of ways to set x_1, ..., x__m with true and false (out of total of 2_m ways) so that the equation is satisfied. Since this number can be extremely large, you need to print the answer modulo 109 + 7.

Please, note that some variable may appear twice in one clause, or not appear in the equation at all (but still, setting it to false or true gives different ways to set variables).

娜塔莉亚·罗曼诺娃正在尝试测试神盾局(S.H.I.E.L.D.)新交给她的枪支。为了确定测试结果,她需要求解某个方程的解的个数。该方程形式如下:

其中 表示逻辑或(OR), 表示逻辑异或(XOR),而 vi,jv_{i,j} 是若干布尔变量或其否定。娜塔莉亚将方程左侧称为 XNF 公式。每个括号内的子式称为一个子句(clause),而 vi,jv_{i,j} 称为文字(literal)。

在娜塔莉亚所面对的具体方程中,左侧实际上是一个 2-XNF-2 公式,包含变量 x1,x2,…,xmx_1, x_2, \dots, x_m 及其否定。一个 XNF 公式被称为 2-XNF-2,当且仅当满足以下两个条件:

  1. 对每个 1≤i≤n1 \le i \le n,有 ki≤2k_i \le 2,即每个子句中所含文字个数不超过 2;
  2. 每个变量在整个公式中至多出现两次(其本身及其否定的出现次数之和不超过 2)。注意:可能出现某变量自身出现两次,而其否定未在任何子句中出现(反之亦然)。

娜塔莉亚获得了一个含 mm 个变量、共 nn 个子句的公式。请务必参考样例以准确理解公式的具体结构。

娜塔莉亚更擅长实战而非理论推导,因此她请你帮她计算该方程的解的个数。更准确地说,你需要计算将 x1,…,xmx_1, \dots, x_m 各赋值为 true 或 false(共 2m2^m 种赋值方式)中有多少种能使该方程成立。由于该数目可能极大,请输出答案对 109+710^9 + 7 取模的结果。

请注意:某些变量可能在同一子句中重复出现,也可能完全不出现于方程中(但即便如此,将其设为 false 或 true 仍被视为不同的赋值方式)。

输入格式

The first line of input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of clauses and the number of variables respectively.

The next n lines contain the formula. The i-th of them starts with an integer k__i — the number of literals in the i-th clause. It is followed by k__i non-zero integers a__i, 1, ..., a__i, k__i. If a__i, j > 0 then v__i, j is x__a__i, j otherwise it's negation of x - a__i, j (1 ≤ k__i ≤ 2,  - m ≤ a__i, j ≤ m, a__i, j ≠ 0).

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤100 0001 \leq n, m \leq 100\,000),分别表示子句的数量和变量的数量。

接下来的 nn 行描述该逻辑公式。其中第 ii 行首先是一个整数 kik_i,表示第 ii 个子句中文字(literal)的个数;随后是 kik_i 个非零整数 ai,1,…,ai,kia_{i,1}, \dots, a_{i,k_i}。若 ai,j>0a_{i,j} > 0,则对应的文字为变量 xai,jx_{a_{i,j}};否则(即 ai,j<0a_{i,j} < 0)对应的文字为变量 x−ai,jx_{-a_{i,j}} 的否定(即 ¬x−ai,j\neg x_{-a_{i,j}})。(满足 1≤ki≤21 \leq k_i \leq 2,−m≤ai,j≤m-m \leq a_{i,j} \leq m,且 ai,j≠0a_{i,j} \neq 0)

输出格式

Print the answer modulo 1 000 000 007 (109 + 7) in one line.

在一行中输出对 1 000 000 007(即 109+710^9 + 7)取模后的答案。

输入输出样例

  • 输入#1

    6 7
    2 4 -2
    2 6 3
    2 -7 1
    2 -5 1
    2 3 6
    2 -2 -5

    输出#1

    48
  • 输入#2

    8 10
    1 -5
    2 4 -6
    2 -2 -6
    2 -7 9
    2 10 -1
    2 3 -1
    2 -8 9
    2 5 8

    输出#2

    544
  • 输入#3

    2 3
    2 1 1
    2 -3 3

    输出#3

    4

说明/提示

The equation in the first sample is:

The equation in the second sample is:

The equation in the third sample is:

第一个样例中的方程为:

第二个样例中的方程为:

第三个样例中的方程为:

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

首页