https://atcoder.jp/contests/abc310/tasks/abc310_d
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define deb(n) cout << #n << "=" << n << " "
#define debug(n) cout << #n << "=" << n << endl
#define div() cout << "_______________" << endl
const int N = 20;
int n, m, k, ans;
int vis[N], ctr[N][N];
int cnt = 0;
void dfs(int pre, int mx) {
if (pre == n + 1) {
if (mx != m) return;
int flag = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (vis[i] == vis[j] && ctr[i][j]) {
flag = 0;
}
}
}
ans += flag;
}
else {
for (int i = 1; i <= mx + 1; i++) {
vis[pre] = i;
dfs(pre + 1, max(mx, i));
vis[pre] = 0;
}
}
}
void oper() {
cin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
int a, b; cin >> a >> b;
ctr[a][b] = ctr[b][a] = 1;
}
dfs(1, 0);
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1; //cin >> t;
while (t--) oper();
return 0;
}