Problem:
Score : 1200 points

Problem Statement

You are given a simple connected undirected graph G consisting of N vertices and M edges.
The vertices are numbered 1 to N, and the edges are numbered 1 to M.

Edge i connects Vertex a_i and b_i bidirectionally.
It is guaranteed that the subgraph consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a spanning tree of G.

An allocation of weights to the edges is called a good allocation when the tree consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a minimum spanning tree of G.

There are M! ways to allocate the edges distinct integer weights between 1 and M.
For each good allocation among those, find the total weight of the edges in the minimum spanning tree, and print the sum of those total weights modulo 10^{9}+7.

Constraints

All values in input are integers.

2 \leq N \leq 20

N-1 \leq M \leq N(N-1)/2

1 \leq a_i, b_i \leq N

G does not have self-loops or multiple edges.

The subgraph consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a spanning tree of G.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
\vdots
a_M b_M

Output

Print the answer.

Sample Input 1

3 3
1 2
2 3
1 3

Sample Output 1

6

An allocation is good only if Edge 3 has the weight 3. For these good allocations, the total weight of the edges in the minimum spanning tree is 3, and there are two good allocations, so the answer is 6.

Sample Input 2

4 4
1 2
3 2
3 4
1 3

Sample Output 2

50

Sample Input 3

15 28
10 7
5 9
2 13
2 14
6 1
5 12
2 10
3 9
10 15
11 12
12 6
2 12
12 8
4 10
15 3
13 14
1 15
15 12
4 14
1 7
5 11
7 13
9 10
2 7
1 9
5 6
12 14
5 2

Sample Output 3

657573092

Print the sum of those total weights modulo 10^{9}+7.

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N =  20;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

int n, m, CNT[1 << N][(N + 1)* (N + 1) / 2], DP[1 << N][(N + 1) * (N + 1) / 2], F[(1 << N)][N], Nie[(N + 1) * (N + 1) / 2], inv[1 << N];
pii par[N + 10][N + 10];
int M[1 << N][N], pnt[1 << N];
vector<pii> E;
vector<pii> G[N + 10];

void DFS(int jad, int v, int p){
	//cout << jad << ' '<< v << ' ' << p << '\n';
	for (auto u:G[v]){
		if (u.F == p) continue;
		par[jad][u.F] = {v, u.S};
		DFS(jad, u.F, v);
	}
}

inline int add(int a, int b){
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

inline int mul(int a, int b){
	return a * 1ll * b % MOD;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	/*int res = 1;
	int x = 0;
	inv[1] = 0;
	for (int i = 1; i < N; i++){
		res *= 2;
		inv[res] = i;
	}
	for (int i = 0; i < m; i++){
		int v, u;
		cin >> v >> u;
		E.pb({v, u});
		if (i < n - 1) G[v].pb({u, i}), G[u].pb({v, i});
	}
	for (int i = 1; i <= n; i++) DFS(i, i, 0);
	for (int i = n - 1; i < m; i++){
		int v = E[i].F, u = E[i].S;
		while (u != v){
			Nie[i] |= (1 << (par[v][u].S));
			u = par[v][u].F;
		}
	}*/
	n--;
	//cout << "YES" << endl;
	for (int mask = 0; mask < (1 << n); mask++){
		for (int i = n - 1; i < m; i++){
			int res = mask & Nie[i];
			if (__builtin_popcount(res) == 1){
				//cout << "Fuck " << mask << ' ' << (res & (-res)) << ' ' << inv[res & (-res)] << '\n';
				F[mask][inv[res & (-res)]] ++;
			}
		}	
		for (int i = 0; i < n; i++) if (mask & (1 << i)) M[mask][pnt[mask]++] = i;
	}
	
	CNT[0][0] = 1;
	for (int mask = 0; mask < (1 << n); mask++) for (int i = 0; i <= m - n; i++){
		if (mask + i == 0) continue;
		if (i != 0) CNT[mask][i] = CNT[mask][i - 1] * 1ll * i % MOD, DP[mask][i] = mul(i, add(DP[mask][i - 1], mul(__builtin_popcount(mask), CNT[mask][i - 1])));
		for (int j = 0; j < pnt[mask]; j++){
			int u = M[mask][j];
			if(mask & (1 << u)) CNT[mask][i] = add(CNT[mask][i], CNT[mask ^ (1 << u)][i + F[mask][u]]),DP[mask][i] = add(DP[mask][i], add(add(DP[mask ^ (1 << u)][i + F[mask][u]], mul(__builtin_popcount(mask ^ (1 << u)), CNT[mask ^ (1 << u)][i + F[mask][u]])), CNT[mask ^ (1 << u)][i + F[mask][u]]));
		}
		//cout << mask << ' ' << j << ' ' << CNT[mask][j] << '\n';
	}
	cout << DP[(1 << n) - 1][0];
	
	return 0;
}