Пример #1
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;
         }
     }
 }
Пример #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]);
             }
         }
     }
 }