解题思路:
注意事项:
参考代码:
n = int(input()) v0 = int(input())-1 matrix = [] M = float("inf") for i in range(n): matrix.append(list(input().split())) for i in range(n): for j in range(n): if matrix[i][j] == "-": matrix[i][j] = M else: matrix[i][j] = int(matrix[i][j]) def dijkstra(matrix,v0): used_node = [False] * n distance = [M] * n distance[v0] = 0 while used_node.count(False): min_value = M min_value_index = -1 for i in range(n): if not used_node[i] and distance[i] < min_value: min_value = distance[i] min_value_index = i if min_value_index == -1: break used_node[min_value_index] = True for i in range(n): distance[i] = min(distance[i],distance[min_value_index]+matrix[min_value_index][i]) return distance distance = dijkstra(matrix,v0) for i in range(0,n): if i == v0: continue print("("+str(v0+1)+" -> "+str(i+1)+") = "+str(distance[i]))
0.0分
0 人评分
2006年春浙江省计算机等级考试二级C 编程题(2) (C++代码)直接打表啊8以上值不变hhh浏览:663 |
C二级辅导-求偶数和 (C语言代码)浏览:659 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:741 |
点我有惊喜!你懂得!浏览:1392 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:607 |
简单的a+b (C语言代码)浏览:689 |
C语言程序设计教程(第三版)课后习题6.3 (Java代码)浏览:695 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:822 |
计算质因子 (C++代码)浏览:1824 |
C语言训练-大、小写问题 (C语言代码)浏览:649 |