목록📖 dfs (2)
즐겁게, 코드
[백준 온라인 저지 링크] 2606번: 바이러스 첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어 www.acmicpc.net [정답 코드 - Python] from collections import deque N = int(input()) T = int(input()) # connection : 컴퓨터 / infected : 감염여부 connection = [0] infected = [False] * (N + 1) # 초기 입력 for _ in range(T): connection.append(list(map(int, input().split()))) def DF..
특이한 점은 없는 탐색 문제다. 오랜만에 푸는 탐색 문제다 보니 DFS 코드를 어떻게 구현할지 고민을 많이 했었는데, 그래도 감을 더듬어가며 코드를 짜니 금방 풀렸다. [정답 코드 - Python] T = int(input()) dy = [1, 0, -1, 0] dx = [0, 1, 0, -1] def DFS(row, col, visited): for i in range(4): new_row = row + dy[i] new_col = col + dx[i] if field[new_row][new_col] == 1 and visited[new_row][new_col] == False: visited[new_row][new_col] = True DFS(new_row, new_col, visited) for _..