diff --git "a/H0ngJu/BFS/\354\240\201\353\241\235\354\203\211\354\225\275.py" "b/H0ngJu/BFS/\354\240\201\353\241\235\354\203\211\354\225\275.py" new file mode 100644 index 00000000..e9bcc841 --- /dev/null +++ "b/H0ngJu/BFS/\354\240\201\353\241\235\354\203\211\354\225\275.py" @@ -0,0 +1,46 @@ +import sys +sys.setrecursionlimit(10**6) +from collections import deque + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) +arr = [[i for i in input()]for _ in range(N)] +visited = [[0] * N for _ in range(N)] +direc = [(1,0), (-1,0), (0,1), (0,-1)] +result = [0, 0] + +def bfs(x, y, color): + q = deque([(x,y)]) + visited[x][y] = 1 + while q: + cx, cy = q.popleft() + for dx, dy in direc: + nx = dx + cx + ny = dy + cy + if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny] and arr[nx][ny] == color: + q.append((nx, ny)) + visited[nx][ny] = 1 + + +for i in range(N): + for j in range(N): + if not visited[i][j]: + bfs(i,j,arr[i][j]) + result[0] += 1 + +visited = [[0] * N for _ in range(N)] + +for i in range(N): + for j in range(N): + if arr[i][j] == "R": + arr[i][j] = "G" + +for i in range(N): + for j in range(N): + if not visited[i][j]: + bfs(i,j,arr[i][j]) + result[1] += 1 + + +print(result[0], result[1], end=" ") \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 2f4207eb..c222cf56 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -18,5 +18,6 @@ | 14차시 | 2024.05.09 | DFS | [치킨배달](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 | | 15차시 | 2024.05.14 | 그리디 | [A와 B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 | | 16차시 | 2024.05.14 | BFS | [뱀과 사다리 게임](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 | +| 17차시 | 2024.05.22 | BFS | [적록색약](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 | ---