#P7418. [USACO21FEB] Counting Graphs P

    ID: 8284 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DPUSACO2021O2优化容斥原理

[USACO21FEB] Counting Graphs P

Problem Description

Bessie has a connected undirected graph GG. GG has NN vertices numbered 1N1 \ldots N and MM edges (1N1021 \le N \le 10^2, N1MN2+N2N-1 \le M \le \frac{N^2+N}{2}). GG may contain self-loops (an edge from a vertex to itself), but it does not contain multiple edges (multiple edges connecting the same pair of vertices).

Let fG(a,b)f_G(a,b) be a boolean function. For each 1aN1 \le a \le N and 0b0 \le b, the function is true if there exists a path from vertex 11 to vertex aa that uses exactly bb edges, and false otherwise. If an edge is traversed multiple times, it is counted that many times.

Elsie wants to copy Bessie. Specifically, she wants to construct an undirected graph GG' such that for all aa and bb, we have fG(a,b)=fG(a,b)f_{G'}(a,b)=f_G(a,b).

Your task is to compute the number of graphs GG' that Elsie can construct, modulo 109+710^9+7. Just like GG, GG' may contain self-loops but cannot contain multiple edges (this means that for NN labeled vertices there are 2N2+N22^{\frac{N^2+N}{2}} different graphs in total).

Each input contains TT (1T10541 \le T \le \frac{10^5}{4}) independent test cases. It is guaranteed that the sum of N2N^2 over all test cases does not exceed 10510^5.

Input Format

The first line of input contains TT, the number of test cases.

The first line of each test case contains integers NN and MM.

Each of the next MM lines of the test case contains two integers xx and yy (1xyN1 \le x \le y \le N), meaning that there is an edge connecting xx and yy in GG.

For readability, adjacent test cases are separated by a blank line.

Output Format

For each test case, output one line: the number of different graphs GG', modulo 109+710^9+7.

1

5 4
1 2
2 3
1 4
3 5
3
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
45
35
11
1
15
371842544
256838540

Hint

Explanation for Sample 1:

In the first test case, GG' can be equal to GG, or one of the following two graphs:

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

Explanation for Sample 2:

There are some larger test cases. Make sure your answer is taken modulo 109+710^9+7. Note that the answer for the second-to-last test case is 245(mod109+7)2^{45}\pmod{10^9+7}.

Test Point Properties:

  • For an additional 5%5\% of the testdata, N5N \le 5.
  • For an additional 10%10\% of the testdata, M=N1M = N-1.
  • For an additional 30%30\% of the testdata, if it is not true that for all bb we have fG(x,b)=fG(y,b)f_G(x,b)=f_G(y,b), then there exists bb such that fG(x,b)f_G(x,b) is true and fG(y,b)f_G(y,b) is false.
  • For an additional 45%45\% of the testdata, there are no additional constraints.

Problem by: Benjamin Qi.

Translated by ChatGPT 5