QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#2027. 计数图

统计

Bessie 有一个连通无向图 $G$,包含 $N$ 个顶点,编号为 $1\ldots N$,以及 $M$ 条边($2\le N\le 10^2, N-1\le M\le \frac{N^2+N}{2}$)。$G$ 可能包含自环(从节点指向自身的边),但没有重边(连接相同端点的多条边)。

设 $f_G(a,b)$ 为一个布尔函数,对于所有 $1\le a\le N$ 和 $0\le b$,如果存在一条从顶点 $1$ 到顶点 $a$ 且恰好经过 $b$ 条边的路径,则该函数值为真,否则为假。如果一条边被多次经过,则在计数中需计入相应的次数。

Elsie 想要复制 Bessie 的图。具体来说,她想要构造一个无向图 $G'$,使得对于所有的 $a$ 和 $b$,都有 $f_{G'}(a,b)=f_G(a,b)$。

你的任务是计算 Elsie 可以构造出的不同图 $G'$ 的数量,结果对 $10^9+7$ 取模。与 $G$ 一样,$G'$ 可能包含自环,但没有重边(这意味着在 $N$ 个带标号顶点上总共有 $2^{\frac{N^2+N}{2}}$ 种不同的图)。

每个输入包含 $T$ ($1\le T\le \frac{10^5}{4}$) 个测试用例,应独立求解。保证所有测试用例的 $N^2$ 之和不超过 $10^5$。

输入格式

第一行包含 $T$,即测试用例的数量。

每个测试用例的第一行包含整数 $N$ 和 $M$。

每个测试用例的接下来 $M$ 行,每行包含两个整数 $x$ 和 $y$ ($1\le x\le y\le N$),表示 $G$ 中存在一条连接 $x$ 和 $y$ 的边。

连续的测试用例之间用空行分隔,以提高可读性。

输出格式

对于每个测试用例,输出一行,表示不同图 $G'$ 的数量,对 $10^9+7$ 取模的结果。

样例

样例输入 1

1

5 4
1 2
2 3
1 4
3 5

样例输出 1

3

在第一个测试用例中,$G'$ 可以等于 $G$ 或者以下两个图之一:

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

样例输入 2

7

4 6
1 2
2 3
3 4
1 3
2 4
1 4

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

5 7
1 2
1 3
1 5
2 4
3 3
3 4
4 5

6 6
1 2
2 3
3 4
4 5
5 6
6 6

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

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

22 28
1 2
2 3
3 4
4 5
5 6
6 7
1 7
1 8
3 9
8 10
10 11
10 12
10 13
10 14
11 15
12 16
13 17
14 18
9 15
9 16
9 17
9 18
15 19
19 20
15 20
16 21
21 22
16 22

样例输出 2

45
35
11
1
15
371842544
256838540

这些是一些较大的测试用例。请确保输出结果对 $10^9+7$ 取模。注意倒数第二个测试用例的答案是 $2^{45}\pmod{10^9+7}$。

子任务

  • 输入 3 中的所有测试用例满足 $N\le 5$。
  • 输入 4-5 中的所有测试用例满足 $M=N-1$。
  • 对于输入 6-11 中的所有测试用例,如果不存在对于所有 $b$ 都有 $f_G(x,b)=f_G(y,b)$ 的情况,则一定存在某个 $b$ 使得 $f_G(x,b)$ 为真而 $f_G(y,b)$ 为假。
  • 输入 12-20 中的测试用例不满足额外约束。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.