From 6702886d946660386266442cdf7a01ab49f58347 Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Sun, 1 Sep 2024 02:15:51 +0900 Subject: [PATCH] 74-tgyuuAn --- tgyuuAn/README.md | 1 + .../\353\266\210 \354\274\234\352\270\260.py" | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 "tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 6e403df7..492b2333 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -78,4 +78,5 @@ | 69차시 | 2024.08.10 | 누적합, 수학 | 1의 개수 세기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/228 | 70차시 | 2024.08.16 | 스택 | 탑 보기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/232 | 71차시 | 2024.08.20 | 다익스트라 | 다익스트라 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/235 +| 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