[Ch.10 - 그래프 이론] 도시 분할 계획
My code def find_parent(parent, x): if parent[x] != x: parent[x] = find_parent(parent, parent[x]) return parent[x] def union_parent(parent, a, b): a = find_parent(parent, a) b = find_parent(parent, b) if a < b: parent[b] = a else: parent[a] = b n, m = map(int,input().split()) parent = [0] * (n + 1) edges = [] for i in range(1, n + 1): parent[i] = i for i in range(m): a, b, cost = map(int,input()..
2022. 2. 20.
[Ch. 10 - 그래프 이론] 팀 결성
My code def find_parent(parent, x): if parent[x] != x: parent[x] = find_parent(parent, parent[x]) return parent[x] def union_parent(parent, a, b): a = find_parent(parent, a) b = find_parent(parent, b) if a < b: parent[b] = a else: parent[a] = b n, m = map(int,input().split()) parent = [0] * (n + 1) for i in range(1, n + 1): parent[i] = i for i in range(m): a, b, c = map(int, input().split()) if ..
2022. 2. 20.
[Ch. 9 - 최단 경로] 전보
My code import heapq INF = int(1e9) n, m, c = map(int,input().split()) graph = [[] for i in range(n + 1)] distance = [INF] * (n + 1) for i in range(m): x, y, z = map(int,input().split()) graph[x].append((y, z)) def dijkstra(c): q = [] distance[c] = 0 heapq.heappush(q, (0, c)) while q: dist, now = heapq.heappop(q) if distance[now] < dist: continue for i in graph[now]: cost = dist + i[1] if cost <..
2022. 2. 17.