ABC054 C - One-stroke Path
https://atcoder.jp/contests/abc054/tasks/abc054_c
提出
code: python
from collections import deque
n, m = map(int, input().split())
ab = list(map(int, input().split())) for _ in range(n)
graph = [[] for _ in range(n+1)]
visited = False for _ in range(n+1)
for i in ab:
graph[i0].append(i1)
graph[i1].append(i0)
print(graph)
que = deque([graph1])
ans = 0
while que:
next = que.popleft()
for i in next:
if not (visitedi):
visitedi = True
que.append(graphi)
print(visited)
解答
code: python
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
pathab = True
pathba = True
# print(path)
# False, True, True], True, False, True, [True, True, False
ans = 0
# 頂点を並び替える順列を生成してループ
for i in itertools.permutations(range(n), n):
# print(i)
# (0, 1, 2)
# (0, 2, 1)
# (1, 0, 2)
# (1, 2, 0)
# (2, 0, 1)
# (2, 1, 0)
# 頂点1が始点
if i0 == 0:
# 生成した順列の中をさらにループ
for j in range(n):
# n - 1 まで続いたら条件を満たすパスが存在する
if j == n - 1:
ans += 1
break
# ij から ij + 1 に行くパスがなければ終了
if not path[ij][ij + 1]:
break
print(ans)
テーマ
#graph
メモ
Pythonで解く蟻本(2-1: すべての基本 "全探索")