Language: C++

#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

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

const int N =  21;
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 + 1) * (N + 1)][(N + 1) * (N + 1)];
vector<pii> E;
vi M[1 << N];
vector<pii> G[N];

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});
	}
//	cout << "YES" << endl;
	for (int i = 1; i <= n; i++){
		DFS(i, i, 0);
	}
	//cout << "YES" << endl;
	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;
		}
		//cout << i << ' ' << Nie[i] << '\n';
	}
	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)]] ++;
			}
		}	
	}
	CNT[0][0] = 1;
	for (int mask = 0; mask < (1 << n); mask++){
		for (int i = 0; i < n; i++){
			if (mask & (1 << i)) M[mask].pb(i);
		}
	}
	for (int mask = 0; mask < (1 << n); mask++) for (int j = 0; j <= m - n; j++){
		if (mask + j == 0) continue;
		if (j != 0) CNT[mask][j] = CNT[mask][j - 1] * 1ll * j % MOD;
		for (int u:M[mask]) CNT[mask][j] = add(CNT[mask][j], CNT[mask ^ (1 << u)][j + F[mask][u]]);
		//cout << mask << ' ' << j << ' ' << CNT[mask][j] << '\n';
	}
	DP[0][0] = 0;
	
	for (int mask = 0; mask < (1 << n); mask ++) for (int i = 0; i <= m - n; i++){
		if (mask + i == 0) continue;
		if (i != 0) DP[mask][i] = mul(i, add(DP[mask][i - 1], mul(__builtin_popcount(mask), CNT[mask][i - 1])));
		for (int u:M[mask]){
			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 << DP[(1 << n) - 1][0];
	return 0;
}


Compiler output:
/tmp/ccik4sYs.o: in function `DFS(int, int, int)':
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0xad): relocation truncated to fit: R_X86_64_PC32 against symbol `par' defined in .bss section in /tmp/ccik4sYs.o
/tmp/ccik4sYs.o: in function `main':
a.cc:(.text+0x181): relocation truncated to fit: R_X86_64_PC32 against symbol `inv' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x1a5): relocation truncated to fit: R_X86_64_PC32 against symbol `inv' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x223): relocation truncated to fit: R_X86_64_PC32 against symbol `E' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x25f): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x2ac): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x34b): relocation truncated to fit: R_X86_64_PC32 against symbol `E' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x367): relocation truncated to fit: R_X86_64_PC32 against symbol `E' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x38e): relocation truncated to fit: R_X86_64_PC32 against symbol `Nie' defined in .bss section in /tmp/ccik4sYs.o
a.cc:(.text+0x3b5): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status