6.7 单源最短路径(一) #142
Replies: 8 comments 8 replies
-
Dijkstra解决网络延迟 class Solution(object):
def networkDelayTime(self, times, n, k):
"""
:type times: List[List[int]]
:type n: int
:type k: int
:rtype: int
"""
visited = set()
graph = defaultdict(list)
cut = [(0, k)]
for u, v, t in times:
graph[u].append((t, v))
while cut:
t, v = heapq.heappop(cut)
if v in visited:
continue
visited.add(v)
if len(visited) == n:
return t
for time, node in graph[v]:
if node not in visited:
heapq.heappush(cut, (t+time, node))
return -1 |
Beta Was this translation helpful? Give feedback.
-
#这是用AI生成的Dijkstra算法
|
Beta Was this translation helpful? Give feedback.
-
是我显示的问题吗 2.2 开始全没了 |
Beta Was this translation helpful? Give feedback.
-
为什么不更了啊? |
Beta Was this translation helpful? Give feedback.
-
作者接着更新吧,网上最有用的手册了。觉得比UCB讲得全面。 |
Beta Was this translation helpful? Give feedback.
-
大佬太强了,什么时候更新😍 |
Beta Was this translation helpful? Give feedback.
-
跪求更新 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
6.7 单源最短路径(一)
单源最短路径知识(一) 1. 单源最短路径的定义 单源最短路径(Single Source Shortest Path):对于一个带权图 G=(V,E),其中每条边的权重是一个实数。另外,给定 v 中的一个顶点,称之为源点。则源点到其他所有各个顶点之间的最短路径长度,称为单源最短路径。 这里的路径长度,指的是路径上各边权之和。 单源最短路径问题的核心是...
https://algo.itcharge.cn/06_graph/06_07_graph_shortest_path_01/
Beta Was this translation helpful? Give feedback.
All reactions