Language: C++

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i; return *this;
	}

	template<class c, int=0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return *this << range(begin(i), end(i));
	}

sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII > VP;
typedef vector<PLL > VPL;
typedef vector<double> VD;
typedef long double ld;

VP E;
int n, m;
int p[30];

int P(int a) {
	if (p[a] == a) return a;
	return p[a] = P(p[a]);
}

void Join(int a, int b) {
	a = P(a);
	b = P(b);
	p[a] = b;
}

int Count(int mask) {
	for (int i = 1; i <= n; i++) p[i] = i;
	for (int i = 0; i < n - 1; i++) {
		if (mask & (1 << i));
		else continue;
		Join(E[i].first, E[i].second);
	}

	int ret = 0;
	for (int i = n - 1; i < m; i++) {
		if (P(E[i].first) == P(E[i].second)) {
			ret++;
		}
	}
	return ret;
}

#ifdef LOCAL
const int Z = 20;
#else
const int Z = 19;
#endif

int bit_cnt[1 << Z];
const LL MOD = 1000000007;
int cnt[1 << Z];
PII dp[1 <<19)][191];
PII DP(int mask, int consumed) {
	if (mask == (1<<(n - 1)) - 1 && cnt[mask] == consumed) {
		return { 1, 0 };
	}
	if (dp[mask][consumed].first != -1) {
		return dp[mask][consumed];
	}
	LL ret = 0;
	LL way = 0;
	LL w = bit_cnt[mask] + consumed + 1;
	for (int i = 0; i < n - 1; i++) {
		if (mask & (1 << i)) continue;
		PII p = DP(mask | (1 << i), consumed);
		ret += w * p.first + p.second;
		ret %= MOD;
		way += p.first;
		way %= MOD;
	}
	if (cnt[mask] > consumed) {
		LL nway = (cnt[mask] - consumed);
		PII p = DP(mask, consumed + 1);
		ret += nway * p.second;
		way += p.first * nway;
		ret %= MOD;
		way %= MOD;
	}
	return dp[mask][consumed] = { way, ret };
}

void solve(int ks) {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		E.push_back({ u, v });
	}
	int LIM = 1 << (n - 1);
	for (int i = 0; i < LIM; i++) {
		bit_cnt[i] = 0;
		for (int j = 0; j < n - 1; j++) {
			if (i & (1 << j)) bit_cnt[i]++;
		}
		for (int j = 0; j <= m; j++) {
			dp[i][j] = { -1, -1 };
		}
	}
	for (int i = 0; i < LIM; i++) {
		cnt[i] = Count(i);
	}

	LL ans = DP(0, 0).second;
	printf("%lld\n", ans);
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif


	if (0) {
		int T;
		scanf("%d", &T);
		for (int ks = 1; ks <= T; ks++) solve(ks);
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Compiler output:
a.cc:136:14: error: expected ']' before ')' token
  136 | PII dp[1 <<19)][191];
      |              ^
      |              ]
a.cc: In function 'PII DP(int, int)':
a.cc:141:13: error: 'dp' was not declared in this scope; did you mean 'p'?
  141 |         if (dp[mask][consumed].first != -1) {
      |             ^~
      |             p
a.cc:163:16: error: 'dp' was not declared in this scope; did you mean 'p'?
  163 |         return dp[mask][consumed] = { way, ret };
      |                ^~
      |                p
a.cc: In function 'void solve(int)':
a.cc:180:25: error: 'dp' was not declared in this scope; did you mean 'p'?
  180 |                         dp[i][j] = { -1, -1 };
      |                         ^~
      |                         p