일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 자료구조
- 브루트포스
- 다이나믹 프로그래밍
- GROUP BY
- 구현
- MST
- 트리
- 다익스트라
- 분할정복
- 에라토스테네스의 체
- 다이나믹프로그래밍
- 서브쿼리
- 플로이드-워셜
- 그래프 탐색
- 그래프 이론
- 투포인터
- 크루스칼
- 재귀
- 다시
- DP
- 우선순위큐
- join
- 그리디
- 백트래킹
- 시뮬레이션
- 수학
- DFS
- BFS
- 해시
- 누적합
- Today
- Total
목록그래프 이론 (20)
기록하고 까먹지 말기

날짜 : 2023. 10. 09 사용 언어 : python 문제 코드 다익스트라 import heapq INF = int(1e9) def solution(n, s, a, b, fares): graph = [[] for _ in range(n + 1)] for edge in fares: # 각 노드와 연결된 edge 체크 p, q, cost = edge graph[p].append([q, cost]) graph[q].append([p, cost]) def dijkstra(start, end): dist = [INF] * (n + 1) dist[start] = 0 # 현재노드 queue = list() heapq.heappush(queue, [0, start]) while queue: d, now = hea..

날짜 : 2023. 10. 08 사용 언어 : python 문제 코드 def solution(info, edges): visited = [False] * len(info) # 방문처리 res = list() visited[0] = True res.append(1) def dfs(sheep, wolf): if sheep > wolf: res.append(sheep) else: return for start, end in edges: if visited[start] and not visited[end]: # 부모노드 방문 완료, 자식노드 탐색 visited[end] = True # 방문처리 if info[end] == 0: # 자식이 양 dfs(sheep + 1, wolf) else: dfs(sheep, w..

날짜 : 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. 30 사용 언어 : python 문제 코드 import sys def bt(idx, path): if len(path) == m: if path not in res: res.append(path) return for i in range(idx, n): bt(i, path + [a[i]]) return n, m = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) a.sort() # print(a) res = list() bt(0, []) res.sort() for i in res: print(*i) 풀이 - 기본적인 백트래킹을 활용한 문제 - 조건에 따라 입력받은 후 해당..

날짜 : 2023. 09. 29 사용 언어 : python 문제 코드 def solution(tickets): used = [False] * len(tickets) # 사용여부 res = list() def dfs(now, path): # print(now, path) if len(path) == len(tickets) + 1: res.append(path) return for i in range(len(tickets)): if not used[i] and tickets[i][0] == now: # 현재 체크하는 티켓 사용 x, 출발지가 동일 used[i] = True # 사용체크 dfs(tickets[i][1], path + [tickets[i][1]]) # 리스트간 더하기 used[i] = False..

날짜 : 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. 24 사용 언어 : python 문제 코드 import sys import heapq n, m, x = map(int, sys.stdin.readline().split()) graph = [[] for _ in range(n + 1)] for _ in range(m): start, end, cost = map(int, sys.stdin.readline().split()) graph[start].append([end, cost]) INF = int(1e9) res = list() def dijkstra(start, end): dist = [INF] * (n + 1) # start 기준으로 거리 dist[start] = 0 # 본인 제외 queue = list() heapq.hea..