https://www.acmicpc.net/problem/7576

또 BFS. 그냥 나는 최단 / 최소 이런 문자가 있으면 BFS 로 풀기로 했다. 풀면서 미로탐색이 생각났다.
queue 에다 x, y, count 를 넣고 계속 count 를 업데이트 시켜나갔다.
from collections import deque
m, n = map(int, input().split())
graph = []
for _ in range(n):
graph.append(list(map(int, input().split())))
queue = deque()
for i in range(n):
for j in range(m):
if graph[i][j] == 1:
queue.append((i,j,0))
def bfs():
while queue:
last_count = 0
x,y,count = queue.popleft()
if x-1 >= 0 and graph[x-1][y] == 0:
graph[x-1][y] = 1
queue.append((x-1, y, count+1))
if x+1 < n and graph[x+1][y] == 0:
graph[x+1][y] = 1
queue.append((x+1, y, count+1))
if y-1 >= 0 and graph[x][y-1] == 0:
graph[x][y-1] = 1
queue.append((x, y-1, count+1))
if y+1 < m and graph[x][y+1] == 0:
graph[x][y+1] = 1
queue.append((x, y+1, count+1))
last_count = count
return last_count
result = bfs()
if any( 0 in value for value in graph):
print(-1)
else:
print(result)
numbers = [1,2,3,4,5]
if any(number == 1 for number in numbers):
print('hi')
numbers = [[1,2],[3,4,5]]
# 이차원 리스트에서 특정 값이 있는지 확인할 때는 in 연산자를 사용하여 각 서브리스트를 검사한다.
if any(1 in number for number in numbers):
print('hi')
```