#P17477. [ICPC 2018 Jiaozuo R] Connected Subgraphs

[ICPC 2018 Jiaozuo R] Connected Subgraphs

题目描述

An algorithm master in graph theory would never endure any disconnected subgraph.

An esthetician would only consider edge-induced subgraphs as necessary subgraphs.

An OCD patient would always choose a subgraph from a given simple undirected graph randomly.

Those are why Picard asks you to calculate, for choosing four different edges from a given simple undirected graph with equal probability among all possible ways, the probability that the edge-induced subgraph formed by chosen edges is connected. Here we say a subset of edges in the graph together with all vertices that are endpoints of edges in the subset form an edge-induced subgraph.

To avoid any precision issue, Picard denotes the probability as pp and the number of edges as mm, and you should report the value (p⋅(m4)) mod (109+7)\left(p \cdot \binom{m}{4}\right) \bmod (10^9 + 7). It is easy to show that p⋅(m4)p \cdot \binom{m}{4} is an integer.

输入格式

The input contains several test cases, and the first line contains a positive integer TT indicating the number of test cases which is up to 1010.

For each test case, the first line contains two integers nn and mm indicating the numbers of vertices and edges in the given simple undirected graph respectively, where 4≤n≤1054 \leq n \leq 10^5 and 4≤m≤2×1054 \leq m \leq 2 \times 10^5.

The following mm lines describe all edges of the graph, the ii-th line of which contains two integers uu and vv which represent an edge between the uu-th vertex and the vv-th vertex, where 1≤u,v≤n1 \leq u, v \leq n and u≠vu \neq v.

We guarantee that the given graph contains no loops or multiple edges.

输出格式

For each test case, output a line containing an integer corresponding to the value (p⋅(m4)) mod (109+7)\left(p \cdot \binom{m}{4}\right) \bmod (10^9 + 7), where pp indicates the probability which you are asked to calculate.

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