#P17477. [ICPC 2018 Jiaozuo R] Connected Subgraphs
[ICPC 2018 Jiaozuo R] Connected Subgraphs
Problem Description
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 and the number of edges as , and you should report the value . It is easy to show that is an integer.
Input Format
The input contains several test cases, and the first line contains a positive integer indicating the number of test cases which is up to .
For each test case, the first line contains two integers and indicating the numbers of vertices and edges in the given simple undirected graph respectively, where and .
The following lines describe all edges of the graph, the -th line of which contains two integers and which represent an edge between the -th vertex and the -th vertex, where and .
We guarantee that the given graph contains no loops or multiple edges.
Output Format
For each test case, output a line containing an integer corresponding to the value , where 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