1916번 - 최소비용 구하기
다익스트라에서 방문하지 않은 vertex중에 distance값이 가장 작은 vertex를 반환해주는 함수인 get_min_vertex_not_visited 함수에서 타입에러가 발생하는데 해당 함수를 아래처럼 고치면 해결이 됩니다. 근데 차이점을 잘 모르겠어요..
def get_min_vertex_not_visited(): min_value = INF min_vertex = -1 for vertex in range(1, n+1): if not visited[vertex] and min_value > distance[vertex]: min_value = distance[vertex] min_vertex = vertex return min_vertex
도시들이 모두 연결되지 않을 수 있습니다.
n-1회 반복은 출발 노드부터 다른 n-1개의 노드까지의 최단경로를 모두 구할 때 필요합니다.
아래 예시는 1->3의 최단경로를 찾고자 하지만 1, 2, 3은 연결되어있고, 4는 연결되지 않은 경우입니다.
댓글을 작성하려면 로그인해야 합니다.
minjumost 2년 전
다익스트라에서 방문하지 않은 vertex중에 distance값이 가장 작은 vertex를 반환해주는 함수인 get_min_vertex_not_visited 함수에서 타입에러가 발생하는데 해당 함수를 아래처럼 고치면 해결이 됩니다. 근데 차이점을 잘 모르겠어요..
def get_min_vertex_not_visited():
min_value = INF
min_vertex = -1
for vertex in range(1, n+1):
if not visited[vertex] and min_value > distance[vertex]:
min_value = distance[vertex]
min_vertex = vertex
return min_vertex