<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>obelisk2</author_name>
  <author_url>https://blog.hatena.ne.jp/obelisk2/</author_url>
  <blog_title>Camera Obscura</blog_title>
  <blog_url>https://obelisk.hatenablog.com/</blog_url>
  <categories>
    <anon>Ruby</anon>
    <anon>アルゴリズム</anon>
  </categories>
  <description>前エントリでは閉路なし有向グラフ（DAG）の場合に最短経路を求めてみましたが、ダイクストラ法は閉路があり、かつ辺の重みが非負の場合に最短経路を求めることができます。入出力は、閉路があって辺の重みが非負である以外、DAG の場合と同じなので、そちらを見て下さい。コーディングは Ruby で行いました。返り値は配列 [shortest, pred] で、pred を見ると最短経路がわかります。 dijkstra.rb def dijkstra(graph, start) h = graph.map {|x| [x[0], x[1].keys]}.to_h shortest = Hash.new(F…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fobelisk.hatenablog.com%2Fentry%2F2017%2F08%2F07%2F180132&quot; title=&quot;ダイクストラ法（Ruby） - Camera Obscura&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>http://img.f.hatena.ne.jp/images/fotolife/o/obelisk2/20170807/20170807175016.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2017-08-07 18:01:32</published>
  <title>ダイクストラ法（Ruby）</title>
  <type>rich</type>
  <url>https://obelisk.hatenablog.com/entry/2017/08/07/180132</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
