Пример #1
0
 void UpdateInEdgesOfV(int v)
 {
     foreach (var inEdge in graph.InEdges(v))
     {
         var u = inEdge.Source;
         if (NodeIsInTree(u))
         {
             continue;
         }
         IEdge oldEdge;
         if (hedgehog.TryGetValue(u, out oldEdge))
         {
             var oldWeight = weight(oldEdge);
             var newWeight = weight(inEdge);
             if (newWeight < oldWeight)
             {
                 q.DecreasePriority(u, newWeight);
                 hedgehog[u] = inEdge;
             }
         }
         else
         {
             q.Enqueue(u, weight(inEdge));
             hedgehog[u] = inEdge;
         }
     }
 }
 static IEnumerable <int> Neighbors(BasicGraph <TEdge> graph, int s)
 {
     foreach (TEdge e in graph.OutEdges(s))
     {
         yield return(e.Target);
     }
     foreach (TEdge e in graph.InEdges(s))
     {
         yield return(e.Source);
     }
 }