# swea 1226 '미로'

from collections import deque

T = 10

di = [0, 1, 0, -1]
dj = [1, 0, -1, 0]

for t in range(1, T+1):
    input()
    MAP = []
    N = 16
    for _ in range(N):
        MAP.append(list(map(int, input())))

    for i in range(N):
        for j in range(N):
            if MAP[i][j] == 2:
                st_i, st_j = i, j
            if MAP[i][j] == 3:
                fn_i, fn_j = i, j

    queue = deque()
    queue.append((st_i, st_j))
    MAP[st_i][st_j] = 1

    flag = 0
    while queue:
        i, j = queue.popleft()
        if MAP[i][j] == 3:
            flag = 1
            break

        MAP[i][j] = 1

        for d in range(4):
            next_i = i + di[d]
            next_j = j + dj[d]

            if MAP[next_i][next_j] == 1:
                continue

            queue.append((next_i, next_j))

    print('#{} {}'.format(t, flag))

'알고리즘 문제 풀이 > SWEA' 카테고리의 다른 글

[SWEA 1224 python] 계산기3  (0) 2021.08.24
[SWEA 1223 python] 계산기2  (0) 2021.08.23
[SWEA 1219 python] 길찾기  (0) 2021.08.19
[SWEA 1234 python] 비밀번호  (0) 2021.08.19
[SWEA 2005 python] 파스칼의 삼각형  (0) 2021.08.18

+ Recent posts