-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.py
55 lines (44 loc) · 1.1 KB
/
C.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
N, M = map(int, input().split())
#ab = [list(map(int, input().split())) for i in range(M)]
ab = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int,input().split())
ab[a-1].append(b-1)
ab[b-1].append(a-1)
#print(ab)
count = 0
def dfs(i, now, done):
global count
if i == N-1:
count += 1
#print(now+1)
#print('-----')
return
for j in ab[now]:
#print(j, done)
if j not in done:
#print(j+1)
#done.append(j)
dfs(i+1, j, done + [j])##引数はバラして入れる!
return
dfs(0, 0, [0])
print(count)
# import itertools
# n, m = map(int, input().split())
# path = [[False] * n for i in range(n)]
# for i in range(m):
# a, b = map(int, input().split())
# a -= 1
# b -= 1
# path[a][b] = True
# path[b][a] = True
# ans = 0
# for i in itertools.permutations(range(n), n):#N!
# if i[0] == 0:
# for j in range(n):
# if j == n - 1:
# ans += 1
# break
# if not path[i[j]][i[j + 1]]:
# break
# print(ans)