title: Dijkstra's Algorithm Issue
body: <p>I'm working on a program where I have to find the shortest path between 12 cities, starting in Seattle and ending in Miami. I'm using Dijkstra's Algorithm because the paths are weighted. Here is my code so far, it all works except the answer I get is not the one I need, although it is correct.</p>
  
  <p>This part of the code sets everything up as well as creates the sorting algorithm.</p>
  
  <pre><code>class Graph
  {
      Dictionary&lt;string, Dictionary&lt;string, int&gt;&gt; vertices = new Dictionary&lt;string, Dictionary&lt;string, int&gt;&gt;();
  
      public void add_vertex(string name, Dictionary&lt;string, int&gt; edges)
      {
          vertices[name] = edges;
      }
  
      public List&lt;string&gt; shortest_path(string start, string finish)
      {
          var previous = new Dictionary&lt;string, string&gt;();
          var distances = new Dictionary&lt;string, int&gt;();
          var nodes = new List&lt;string&gt;();
  
          List&lt;string&gt; path = null;
  
          foreach (var vertex in vertices)
          {
              if (vertex.Key == start)
              {
                  distances[vertex.Key] = 1;
              }
              else
              {
                  distances[vertex.Key] = int.MaxValue;
              }
  
              nodes.Add(vertex.Key);
          }
  
          while (nodes.Count != 0)
          {
              nodes.Sort((x, y) =&gt; distances[x] - distances[y]);
  
              var smallest = nodes[0];
              nodes.Remove(smallest);
  
              if (smallest == finish)
              {
                  path = new List&lt;string&gt;();
                  while (previous.ContainsKey(smallest))
                  {
                      path.Add(smallest);
                      smallest = previous[smallest];
                  }
  
                  break;
              }
  
              if (distances[smallest] == int.MaxValue)
              {
                  break;
              }
  
              foreach (var neighbor in vertices[smallest])
              {
                  var alt = distances[smallest] + neighbor.Value;
                  if (alt &lt; distances[neighbor.Key])
                  {
                      distances[neighbor.Key] = alt;
                      previous[neighbor.Key] = smallest;
                  }
              }
          }
  
          return path;
      }
  }
  </code></pre>
  
  <p>Below is where I create the "cities" along with creating the values between them.</p>
  
  <pre><code>class MainClass
  {
      public static void Main(string[] args)
      {
          Graph g = new Graph();
          g.add_vertex("Seattle", new Dictionary&lt;string, int&gt;() { {"San Francisco", 1306}, {"Denver", 2161}, {"Minneapolis", 2661} });
          g.add_vertex("San Francisco", new Dictionary&lt;string, int&gt;() { {"Seattle", 1306}, {"Las Vegas", 919}, {"Los Angeles", 629} });
          g.add_vertex("Las Vegas", new Dictionary&lt;string, int&gt;() { {"San Francisco", 919}, {"Los Angeles", 435}, {"Denver", 1225}, {"Dallas", 1983} });
          g.add_vertex("Los Angeles", new Dictionary&lt;string, int&gt;() { {"San Francisco", 629}, {"Las Vegas", 435} });
          g.add_vertex("Denver", new Dictionary&lt;string, int&gt;() { {"Seattle", 2161}, {"Las Vegas", 1225}, {"Minneapolis", 1483}, {"Dallas", 1258} });
          g.add_vertex("Minneapolis", new Dictionary&lt;string, int&gt;() { {"Seattle", 2661}, {"Denver", 1483}, {"Dallas", 1532}, {"Chicago", 661} });
          g.add_vertex("Dallas", new Dictionary&lt;string, int&gt;() { {"Las Vegas", 1983}, {"Denver", 1258}, {"Minneapolis", 1532}, {"Washington DC", 2113} });
          g.add_vertex("Chicago", new Dictionary&lt;string, int&gt;() { {"Minneapolis", 661}, {"Washington DC", 1145}, {"Boston", 1613} });
          g.add_vertex("Washington DC", new Dictionary&lt;string, int&gt;() { {"Dallas", 2113}, {"Chicago", 1145}, {"Boston", 725}, {"New York", 383}, {"Miami", 1709} });
          g.add_vertex("Boston", new Dictionary&lt;string, int&gt;() { {"Chicago", 1613}, {"Washington DC", 725}, {"New York", 338} });
          g.add_vertex("New York", new Dictionary&lt;string, int&gt;() { {"Washington DC", 383}, {"Boston", 338}, {"Miami", 2145} });
          g.add_vertex("Miami", new Dictionary&lt;string, int&gt;() { {"Dallas", 2161}, {"Washington DC", 1709}, {"New York", 2145} });
  
          g.shortest_path("Miami", "Seattle").ForEach(x =&gt; Console.Write(x + " &gt; "));
      }
  }
  </code></pre>
  
  <p>The part that I need help figuring out is when I run the program, I get: Seattle > Denver > Dallas. That answer is correct for the shortest distance to Miami, but I need the shortest distance to every city, not just Miami. I just don't know what I need to change to display that properly.</p>