# 迪杰斯特拉算法怎么写，我这里出了错误

``````using Graph: findEdges, AdjList
@enum Color begin
White
Grey
Black
end

function dijkstra(graph::UnDirectedGraph{T}, startvertex::T, endvertex::T) where T
distancemap = Dict{T, Number}()
visitedmap = Dict{T, Color}()

end

visitedmap[startvertex] = Black
distancemap[startvertex] = 0

for edge in findEdges(graph, startvertex)
visitedmap[edge.vertex] = Grey
distancemap[edge.vertex] = edge.weight
end

flag = all(x -> x[2] == Black, collect(visitedmap))
while !flag

# here I can use heap
end

minvertex = extract!(heap).vertex
visitedmap[minvertex] = Black

edges = filter(edge -> visitedmap[edge.vertex] != Black, findEdges(graph, minvertex))

for edge in edges
visitedmap[edge.vertex] = Grey
distancemap[edge.vertex] = min(distancemap[edge.vertex],
distancemap[minvertex] + edge.weight)
end

flag = all(x -> x[2] == Black, collect(visitedmap))
@info "the visited map is" visitedmap
end

return distancemap[endvertex]
end
``````

``````  graph = UnDirectedGraph(Char)
for vertex in 'A':'G'
insertVertex!(graph, vertex)
end

insertEdge!(graph, 'A', 'B', 5)
insertEdge!(graph, 'A', 'C', 2)
insertEdge!(graph, 'B', 'D', 1)
insertEdge!(graph, 'B', 'E', 6)
insertEdge!(graph, 'C', 'D', 6)
insertEdge!(graph, 'C', 'F', 8)
insertEdge!(graph, 'D', 'E', 1)
insertEdge!(graph, 'D', 'F', 2)
insertEdge!(graph, 'E', 'G', 7)
insertEdge!(graph, 'F', 'G', 3)

@show dijkstra(graph, 'A', 'G')
``````

https://cn.julialang.org/LeetCode.jl/dev/democards/problems/problems/743.network-delay-time/

https://cn.julialang.org/LeetCode.jl/dev/democards/problems/problems/778.swim-in-rising-water/
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://discourse.juliacn.com/t/topic/6447", "fetch_time": 1659977358000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2022-33/segments/1659882570868.47/warc/CC-MAIN-20220808152744-20220808182744-00521.warc.gz", "warc_record_offset": 227751775, "warc_record_length": 4996, "token_count": 518, "char_count": 1603, "score": 3.5625, "int_score": 4, "crawl": "CC-MAIN-2022-33", "snapshot_type": "latest", "language": "en", "language_score": 0.5673496723175049, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00063-of-00064.parquet"}