1491 圆桌座位
作者:
jy9
,
2024-11-26 21:05:40
,
所有人可见
,
阅读 4
题目链接
#include <iostream>
#include <cstring>
#include <unordered_map>
using namespace std;
int mp[15][15];
int n, m;
int ans;
bool st[15];
int res[15];
void dfs(int u){
if(u == n+1){
if(mp[1][res[n]] || mp[res[n]][1])return;
ans ++;
return;
}
for(int i = 1; i <= n; i++){
if(st[i]) continue;
if(mp[res[u-1]][i] || mp[i][res[u-1]]) continue;
st[i] = 1;
res[u] = i;
dfs(u+1);
st[i] = 0;
}
}
int main(){
memset(res, 0, sizeof res);
memset(st, 0, sizeof st);
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
mp[a][b] = 1;
mp[b][a] = 1;
}
st[1] = 1;
res[1] = 1;
dfs(2);
cout << ans;
return 0;
}