import copy n, m = map(int, input().split()) y, x, d = map(int, input().split()) graph = [] wall = [] for i in range(n): tmp = list(map(int, input().split())) graph.append(tmp) wall = copy.deepcopy(graph) graph[y][x] = 1 answer = 1 cnt = 0 dx = [0, 1, 0, -1] dy = [-1, 0, 1, 0] while True: if cnt == 4: nx = x - dx[d] ny = y - dy[d] if 0
def dfs(graph, i, visited, array): visited[i] = 1 array.append(i) for j in graph[i]: if visited[j] == 0: array = dfs(graph, j, visited, array) return array def solution(n, wires): count = 0 answer = [] while count != len(wires): graph = [[] for _ in range(n)] visited = [0] * n for idx, wire in enumerate(wires): if idx != count: graph[wire[0]-1].append(wire[1]-1) graph[wire[1]-1].append(wire[0]-1..
def dfs(place, x, y, distance, visited): distance = distance + 1 visited[x][y] = 1 dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] if distance > 2: return True else: for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx = 5 or ny = 5: continue elif visited[nx][ny] == 0: if place[nx][ny] == 'P': return False elif place[x+dx[i]][y+dy[i]] == 'X': continue elif place[x+dx[i]][y+dy[i]] =..
DFS로 푼 문제. 코테에도 DFS & BFS 이정도로만 나와주면 안되나요..? graph = [] def dfs(x, visited): if visited[x] == 0: visited[x] = 1 for i in range(len(graph)): if graph[x][i] == 1 and i != x: dfs(i, visited) return True return False def solution(n, computers): answer = 0 for i in range(n): graph.append(computers[i]) visited = [0] * n for i in range(n): if dfs(i, visited) == True: answer = answer + 1 return answer
import sys sys.setrecursionlimit(10000) n = int(input()) graph = [] visited = [] def dfs(x, y, w, h): if x = w or y = h: return False if graph[x][y] != 0: graph[x][y] = 0 dfs(x-1, y, w, h) dfs(x+1, y, w, h) dfs(x, y-1, w, h) dfs(x, y+1, w, h) return True return False answer = [] for _ in range(n): graph = [] w, h, c = map(int, input().split()) for _ in range(w): graph.append([0]*h) for _ in rang..
오늘은 bfs, dfs 문제 다 풀어야지이! n = int(input()) m = int(input()) graph = [[] for _ in range(n+1)] visited = [0]*(n+1) for _ in range(m): v1, v2 = map(int, input().split()) graph[v1].append(v2) graph[v2].append(v1) def dfs(v, count): visited[v] = 1 count = count + 1 for i in graph[v]: if visited[i] == 0: count = dfs(i, count) return count count = 0 count = dfs(1, count) print(count-1) 전형적인 쉬운 dfs 문제. 마..
- Total
- Today
- Yesterday
- CUDA
- PIP
- 카카오
- 설치
- version
- 프로그래머스
- dfs
- 백트래킹
- notfound
- 파이썬
- docker
- torch
- matplotlib
- pytorch
- 동적프로그래밍
- 백준
- n과m
- numpy
- torchscript
- 설치하기
- tensorflow
- error
- 코딩테스트
- 최소신장트리
- shellscript
- BFS
- Python
- 다익스트라
- LGSVL
- 이것이코딩테스트다
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |