from typing import List, Tuple
class Computer:
def __init__(self, num: int):
self.num = num
self.connections = []
def add_connection(self, other: 'Computer', cost: int):
self.connections.append((other, cost))
def find_min_cost(n: int, p: int, k: int, connections: List[Tuple[int, int, int]]) -> int:
computers = {num: Computer(num) for num in range(1, n+1)}
for a, b, cost in connections:
computers[a].add_connection(computers[b], cost)
computers[b].add_connection(computers[a], cost)
queue = [(0, k, computers[1])]
visited = set()
while queue:
cost, free_connections, node = heapq.heappop(queue)
if node in visited:
continue
visited.add(node)
if node.num == n:
return cost
'호그와트' 카테고리의 다른 글
지구를 지켜라 (0) | 2022.12.21 |
---|---|
빨간약 먹을래? 파란약 먹을래? (0) | 2022.12.20 |
우리 모두 홍진호가 되어봅시다 우리 모두 홍진호가 되어봅시다 (1) | 2022.12.15 |
이것만 읽어서는 절대로 이해할 수 없는 버퍼 오버플로우 공격(친절함 없음 주의) (1) | 2022.12.14 |
태양계 영어 이름으로 출력 (0) | 2022.12.14 |