01. 单源最短路径知识(一) #142
Replies: 6 comments 1 reply
-
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.
0 replies
-
#这是用AI生成的Dijkstra算法
|
Beta Was this translation helpful? Give feedback.
0 replies
-
是我显示的问题吗 2.2 开始全没了 |
Beta Was this translation helpful? Give feedback.
1 reply
-
为什么不更了啊? |
Beta Was this translation helpful? Give feedback.
0 replies
-
作者接着更新吧,网上最有用的手册了。觉得比UCB讲得全面。 |
Beta Was this translation helpful? Give feedback.
0 replies
-
大佬太强了,什么时候更新😍 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
01. 单源最短路径知识(一)
单源最短路径知识(一) 1. 单源最短路径的定义 单源最短路径(Single Source Shortest Path):对于一个带权图 G=(V,E),其中每条边的权重是一个实数。另外,给定 v 中的一个顶点,称之为源点。则源点到其他所有各个顶点之间的最短路径长度,称为单源最短路径。 这里的路径长度,指的是路径上各边权之和。 单源最短路径问题的核心是...
https://algo.itcharge.cn/08.Graph/04.Graph-Shortest-Path/01.Graph-Single-Source-Shortest-Path-01/
Beta Was this translation helpful? Give feedback.
All reactions