Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

74-tgyuuAn #242

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@
| 71์ฐจ์‹œ | 2024.08.20 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/24042">๋‹ค์ต์ŠคํŠธ๋ผ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/235
| 72์ฐจ์‹œ | 2024.08.23 | DFS + ํŠธ๋ฆฌ | <a href="https://www.acmicpc.net/problem/20188">๋“ฑ์‚ฐ ๋งˆ๋‹ˆ์•„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/238
| 73์ฐจ์‹œ | 2024.08.26 | BFS | <a href="https://www.acmicpc.net/problem/14324">Rain (Small)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/239
| 74์ฐจ์‹œ | 2024.08.30 | BFS | <a href="https://www.acmicpc.net/problem/11967">๋ถˆ ์ผœ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242
---
Original file line number Diff line number Diff line change
@@ -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))