QOJ.ac

QOJ

حد الوقت: 3.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#18198. 平面精确覆盖

الإحصائيات

农贸市场在二维平面上有 $N$ 个摊位和 $M$ 个仓库。有 $6M$ 条道路,每条道路连接一个摊位和一个仓库,使得除端点外任意两条道路都不相交。换句话说,摊位和仓库构成了一个平面二分图。此外,每个仓库都恰好连接到 $6$ 个不同的摊位。

Busy Beaver 想要选择一个仓库的子集,使得每个摊位都恰好通过一条道路连接到该子集中的一个仓库。有多少种选择这样一个子集的方法?由于答案可能很大,请输出其模 $10^9 + 7$ 的余数。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^4$) —— 测试用例的数量。

每个测试用例的第一行包含两个整数 $N$ 和 $M$ ($6 \le N \le 3 \cdot 10^5$, $N/6 \le M \le 10^5$, $N \equiv 0 \pmod 6$),分别表示摊位的数量和仓库的数量。

接下来的 $M$ 行中,第 $i$ 行以整数 $6$ 开头,后跟 $6$ 个互不相同的整数 $a_{i1}, \dots, a_{i6}$ ($1 \le a_{ij} \le N$ 对于所有 $1 \le j \le 6$),按顺时针顺序描述连接到第 $i$ 个仓库的摊位。

接下来的 $N$ 行中,第 $i$ 行以一个整数 $d_i$ ($1 \le d_i \le M$) 开头,后跟 $d_i$ 个互不相同的整数 $b_{i1}, \dots, b_{id_i}$ ($1 \le b_{ij} \le M$ 对于所有 $1 \le j \le d_i$),按顺时针顺序描述连接到第 $i$ 个摊位的仓库。

保证输入描述了一个平面组合嵌入(planar combinatorial embedding)。

所有测试用例中 $N$ 的总和不超过 $3 \cdot 10^5$。

所有测试用例中 $M$ 的总和不超过 $10^5$。

输出格式

对每个测试用例输出一个整数:选择方法的数量模 $10^9 + 7$ 的余数。

子任务

本题有两个子任务。

  • (50 分):所有测试用例中 $N$ 的总和不超过 $3 \cdot 10^3$,且所有测试用例中 $M$ 的总和不超过 $10^3$。
  • (50 分):无附加限制。

样例

输入 1

2
12 4
6 1 2 3 4 5 6
6 7 8 9 10 11 12
6 4 3 2 1 12 11
6 10 9 8 7 6 5
2 1 3
2 1 3
2 1 3
2 1 3
2 1 4
2 1 4
2 2 4
2 2 4
2 2 4
2 2 4
2 2 3
2 2 3
12 4
6 1 2 3 4 5 6
6 6 7 8 9 10 11
6 1 12 6 11 10 9
6 8 7 6 5 4 3
2 1 3
1 1
2 1 4
2 1 4
2 1 4
4 1 4 2 3
2 2 4
2 2 4
2 2 3
2 2 3
2 2 3
1 3

输出 1

2
0

说明

在第一个测试用例中,仓库和摊位如下所示:

有 2 种选择子集的方法:要么选择仓库 1 和 2,要么选择仓库 3 和 4。

在第二个测试用例中,仓库和摊位如下所示:

注意,连接到摊位 6 的仓库按顺时针顺序排列为:1, 4, 2, 3。不存在任何一种选择仓库子集的方法,使得每个摊位都恰好连接到恰好一个被选中的仓库。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.