일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 그리디
- 시뮬레이션
- 재귀
- MST
- 수학
- 누적합
- GROUP BY
- DFS
- 해시
- 구현
- join
- BFS
- 다시
- 에라토스테네스의 체
- 다이나믹프로그래밍
- 트리
- 브루트포스
- 다익스트라
- 백트래킹
- 크루스칼
- 그래프 탐색
- 다이나믹 프로그래밍
- DP
- 자료구조
- 서브쿼리
- 분할정복
- 그래프 이론
- 우선순위큐
- 플로이드-워셜
- 투포인터
- Today
- Total
목록BFS (24)
기록하고 까먹지 말기

날짜 : 2023. 10. 06 사용 언어 : python 문제 코드 from collections import deque def solution(graph): n, m = len(graph), len(graph[0]) # 행, 열 dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] def bfs(r, c): queue = deque() queue.append([r, c]) cnt = int(graph[r][c]) while queue: x, y = queue.popleft() for i in range(4): nx, ny = x + dx[i], y + dy[i] if nx in range(n) and ny in range(m): # 범위 확인 if not visited[nx][ny] a..

날짜 : 2023. 10. 01 사용 언어 : python 문제 코드 from collections import deque def solution(n, wires): def bfs(idx): queue = deque() queue.append(1) visited = [False] * (n + 1) visited[1] = True cnt = 0 while queue: now = queue.popleft() cnt += 1 for i in range(len(wires)): if i == idx: continue # 사용 불가능한 와이어 if now in wires[i]: # 방문 x, 경로에 있는 경우 if now == wires[i][0] and not visited[wires[i][1]]: visited..

날짜 : 2023. 09. 28 사용 언어 : python 문제 코드 from collections import deque def solution(graph): n, m = len(graph), len(graph[0]) for i in range(n): for j in range(m): if graph[i][j] == 1: graph[i][j] = 0 else: graph[i][j] = 1 answer = 0 queue = deque() queue.append([0, 0]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] while queue: x, y = queue.popleft() if x == (n-1) and y == (m-1): return graph[x][y] + 1 for..

날짜 : 2023. 09. 20 사용 언어 : python 문제 코드 기존 코드(예제 4부터 문제 발생) import sys from collections import deque n = int(sys.stdin.readline()) graph = list() for _ in range(n): graph.append(list(map(int, sys.stdin.readline().split()))) now_r, now_c = 0, 0 # 상어 위치 for i in range(n): for j in range(n): if graph[i][j] == 9: graph[i][j] = 0 # 수정 안했었음 now_r, now_c = i, j # 좌표 설정 break else: continue break dx = [-..
날짜 : 2023. 09. 17 사용 언어 : python 문제 코드 DFS(오답) import sys n, m = map(int, sys.stdin.readline().split()) # 행, 열 graph = list() for _ in range(n): graph.append(" ".join(sys.stdin.readline().rstrip()).split()) visited = [[False] * m for _ in range(n)] visited[0][0] = True dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] def dfs(r, c, flag, cnt): print(r, c, flag, cnt) if (r, c) == (n-1, m-1): print(cnt) exit(..

날짜 : 2023. 07. 25 사용 언어 : python 문제 코드 import sys from collections import deque def bfs(r, c): queue = deque() queue.append([r, c]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] visited[r][c] = True cnt = 0 while queue: x, y = queue.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx in range(n) and ny in range(m) and not visited[nx][ny] and graph[nx][ny] != 'X': visited[nx][ny] = True queu..

날짜 : 2023. 07. 15 사용 언어 : python 문제 코드 import sys from collections import deque def bfs(r, c): queue = deque() queue.append([r, c]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] while queue: x, y = queue.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx in range(n) and ny in range(m) and not visited[nx][ny] and graph[nx][ny] == 1: visited[nx][ny] = True # 방문처리 graph[nx][ny] = graph[x][y] ..

날짜 : 2023. 07. 13 사용 언어 : python 문제 코드 import sys from collections import deque def game(start): res = int(1e9) queue = deque() queue.append([start, 0]) while queue: now, cnt = queue.popleft() # 현재 위치, 주사위 굴린 횟수 # print(now, cnt) if now == 100: # 결승점 도달 print(cnt) return if len(graph[now]) > 6: visited[graph[now][-1]] = True queue.appendleft([graph[now][-1], cnt]) continue for i in graph[now]: i..