목차

알고스팟

ps
링크acmicpc.net/…
출처BOJ
문제 번호1261
문제명알고스팟
레벨골드 4
분류

0-1 BFS

시간복잡도O(nm)
인풋사이즈n<=100, m<=100
사용한 언어Python
제출기록34896KB / 180ms
최고기록72ms
해결날짜2022/09/22

풀이

코드

"""Solution code for "BOJ 1261. 알고스팟".

- Problem link: https://www.acmicpc.net/problem/1261
- Solution link: http://www.teferi.net/ps/problems/boj/1261

Tags: [0-1 BFS]
"""

import sys
from teflib import graph as tgraph
from teflib import search


def main():
    M, N = [int(x) for x in sys.stdin.readline().split()]
    grid = ''.join(input() for _ in range(N))

    graph = tgraph.GridGraph(N, M)
    dists = search.zero_one_distances(
        lambda u: [(v, int(grid[v])) for v in graph[u]], 0, dest=M * N - 1)
    print(dists[M * N - 1])


if __name__ == '__main__':
    main()