diff --git a/hadongun/README.md b/hadongun/README.md index 2db4390..02d568e 100644 --- a/hadongun/README.md +++ b/hadongun/README.md @@ -18,5 +18,6 @@ | 14차시| 2025.05.20 | 트리 | [트리의 부모 찾기] (https://www.acmicpc.net/problem/11725)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/56| | 15차시| 2025.05.21 | 트리 | [트리] (https://www.acmicpc.net/problem/1068)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/58| | 16차시| 2025.06.27 | 구현 | [킹] (https://www.acmicpc.net/problem/1063)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/68| - | 17차시| 2025.07.04 | 두 포인터 | [두 수의 합] (https://www.acmicpc.net/problem/3273)|| + | 17차시| 2025.07.04 | 두 포인터 | [두 수의 합] (https://www.acmicpc.net/problem/3273)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/71| + | 18차시| 2025.07.08 | 그래프 탐색 | [헌내기는 친구가 필요해] (https://www.acmicpc.net/problem/21736)|| --- \ No newline at end of file diff --git "a/hadongun/\355\203\220\354\203\211/\355\227\214\353\202\264\352\270\260\353\212\224 \354\271\234\352\265\254\352\260\200 \355\225\204\354\232\224\355\225\264.py" "b/hadongun/\355\203\220\354\203\211/\355\227\214\353\202\264\352\270\260\353\212\224 \354\271\234\352\265\254\352\260\200 \355\225\204\354\232\224\355\225\264.py" new file mode 100644 index 0000000..d377b9b --- /dev/null +++ "b/hadongun/\355\203\220\354\203\211/\355\227\214\353\202\264\352\270\260\353\212\224 \354\271\234\352\265\254\352\260\200 \355\225\204\354\232\224\355\225\264.py" @@ -0,0 +1,44 @@ +import sys +from collections import deque + +def selflocation(campus, n, m): + result = (0,0) + for i in range(n): + for j in range(m): + if campus[i][j] =='I': + result = (i,j) + return result + + +def exploration(campus, n, m, s): + visited = [[False]*m for _ in range(n)] + directions = ((1, 0), (-1, 0), (0, 1), (0, -1)) + q = deque() + q.append(s) + result = 0 + while q: + y, x = q.popleft() + visited[y][x] = True + for dx, dy in directions: + ny, nx = y + dy, x + dx + + if 0 <= ny <= n-1 and 0 <= nx <= m-1: + if campus[ny][nx] != 'X' and not visited[ny][nx]: + visited[ny][nx] = True + q.append((ny, nx)) + if campus[ny][nx] == 'P': + result += 1 + return result + +input = sys.stdin.readline +n, m = map(int, input().split()) + +campus = [['']*m for _ in range(n)] +for i in range(n): + campus[i] = list(input().strip()) +start = selflocation(campus, n, m) +friend = exploration(campus, n, m, start) +if friend == 0: + print('TT') +else: + print(friend)