Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- n, m = map(int, input().split())
- a = [list(input()) for _ in range(n)]
- x = 0
- for i in range(n):
- for j in range(m):
- if a[i][j] == 'T':
- yt = i
- xt = j
- q = deque()
- q.append([n-2, m-2, 0])
- a[n-2][m-2] = 0
- d = ((0, 1), (0, -1), (1, 0), (-1, 0))
- while q:
- t = q.popleft()
- for e in d:
- yy, xx = t[0]+e[0], t[1]+e[1]
- if str(a[yy][xx]) in '.T':
- a[yy][xx] = t[2] + 1
- q.append([yy, xx, t[2] + 1])
- if a[yt][xt] <= a[1][1]:
- print(a[1][1], '\nNo')
- else:
- print(a[1][1], '\nYes')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement