diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index fca0adc4..cc839c9b 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -80,4 +80,5 @@ | 71차시 | 2024.08.20 | 다익스트라 | 다익스트라 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/235 | 72차시 | 2024.08.23 | DFS + 트리 | 등산 마니아 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/238 | 73차시 | 2024.08.26 | BFS | Rain (Small) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/239 +| 74차시 | 2024.08.30 | BFS | 불 켜기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242 --- diff --git "a/tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" "b/tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" new file mode 100644 index 00000000..a29d53b4 --- /dev/null +++ "b/tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" @@ -0,0 +1,46 @@ +from collections import deque, defaultdict +import sys + +def input(): return sys.stdin.readline().rstrip() + +N, M = map(int, input().split()) +board = [[False for _ in range(N+1)] for _ in range(N+1)] +board[1][1] = True + +switch = defaultdict(list) + +for _ in range(M): + x, y, a, b = map(int, input().split()) + switch[(x, y)].append((a,b)) + +deq = deque() +deq.append((1,1)) +dx = [0, 0, -1, 1] +dy = [-1, 1, 0, 0] +visited = {(1, 1),} +dedicates = {(1, 1),} + +while deq: + now_x, now_y = deq.popleft() + + for turn_on in switch[(now_x, now_y)]: + if turn_on not in dedicates: # <<<------- 이 코드 한줄에 3시간 날림 + dedicates.add(turn_on) + + if turn_on in visited: + deq.append(turn_on) + + for dir in range(4): + new_x = now_x + dx[dir] + new_y = now_y + dy[dir] + + if new_x <= 0 or new_x >= N+1: continue + if new_y <= 0 or new_y >= N+1: continue + if (new_x, new_y) in visited: continue + + visited.add((new_x, new_y)) + + if (new_x, new_y) in dedicates: + deq.append((new_x, new_y)) + +print(len(dedicates)) \ No newline at end of file