Exemple #1
0
 private void Visit(EdgeWeightedGraph G, int v)
 {
     _marked[v] = true;
     foreach (var e in G.Adj(v))
     {
         var w = e.Other(v);
         if (_marked[w])
         {
             continue;
         }
         if (_distTo[w] > e.Weight())
         {
             _edgeTo[w] = e;
             _distTo[w] = e.Weight();
             if (_pq.Contains(w))
             {
                 _pq.Change(w, e.Weight());
             }
             else
             {
                 _pq.Insert(w, e.Weight());
             }
         }
     }
 }
Exemple #2
0
 private void Relax(EdgeWeightedDigraph G, int v)
 {
     foreach (var e in G.Adj(v))
     {
         var w = e.To();
         if (_distTo[w] > _distTo[v] + e.Weight())
         {
             _distTo[w] = _distTo[v] + e.Weight();
             _edgeTo[w] = e;
             if (_pq.Contains(w))
             {
                 _pq.Change(w, _distTo[w]);
             }
             else
             {
                 _pq.Insert(w, _distTo[w]);
             }
         }
     }
 }