AcWing 1491. 圆桌座位
原题链接
简单
作者:
三鹤亥一
,
2025-04-01 13:01:27
· 山东
,
所有人可见
,
阅读 2
N = 11
g =[[0] * N for i in range(N)]
st = [False] * N
pos = [0] * N
def dfs(u):
if u == n:
if g[pos[n - 1]][pos[0]]:
return 0
return 1
res = 0
for i in range(1, n + 1):
if not st[i] and not g[i][pos[u - 1]]:
pos[u] = i
st[i] = True
res += dfs(u + 1)
st[i] = False
return res
n, m = map(int, input().split())
while m:
m -= 1
a, b = map(int, input().split())
g[a][b] = True
g[b][a] = True
pos[0] = 1
st[1] = True
print(dfs(1))