3 //ha predecessor az elejen nem invalid, akkor hagyd csak ugy
4 //scanned mutatja hogy jo ertek van-e benne vagy szemet
7 *template <Graph, T, Heap=FibHeap>
11 *Dijkstra(Graph G, NodeIt s, Graph::EdgeMap<T> length)
18 * The following function should be used after run() was already run.
20 *T dist(NodeIt v) : returns the distance from s to v.
21 * It is 0 if v is not reachable from s.
23 *EdgeIt pred(NodeIt v) : returns the last edge
24 * of a shortest s-v path. Returns an invalid iterator
25 * if v=s or v is not reachable from s.
27 *bool reach(NodeIt v) : true iff v is reachable from s
38 template <typename Graph, typename T,
39 typename Heap=FibHeap<typename Graph::NodeIt, T,
40 typename Graph::NodeMap<int> > >
42 typedef typename Graph::NodeIt NodeIt;
43 typedef typename Graph::EdgeIt EdgeIt;
44 typedef typename Graph::OutEdgeIt OutEdgeIt;
48 typename Graph::NodeMap<EdgeIt> predecessor;
49 typename Graph::NodeMap<T> distance;
50 typename Graph::EdgeMap<T>& length;
51 typename Graph::NodeMap<bool> reached;
56 The distance of the nodes is 0.
58 Dijkstra(Graph& _G, NodeIt const _s,
59 typename Graph::EdgeMap<T>& _length) :
60 G(_G), s(_s), predecessor(G), distance(G),
61 length(_length), reached(G, false) { }
66 typename Graph::NodeMap<bool> scanned(G, false);
67 typename Graph::NodeMap<int> heap_map(G,-1);
74 while ( !heap.empty() ) {
77 T oldvalue=heap.get(v);
79 distance.set(v, oldvalue);
83 for( G.getFirst(e,v); G.valid(e); G.next(e)) {
86 if ( !scanned.get(w) ) {
87 if ( !reached.get(w) ) {
89 heap.push(w,oldvalue+length.get(e));
91 } else if ( oldvalue+length.get(e) < heap.get(w) ) {
93 heap.decrease(w, oldvalue+length.get(e));
102 return distance.get(v);
106 EdgeIt pred(NodeIt v) {
107 if ( v!=s ) return predecessor.get(v);
108 else return EdgeIt();
112 bool reach(NodeIt v) {
113 return reached.get(v);