to it. The vertices have states in the set $\{$[*active*]{}, [*inactive*]{}$\}$. Initially all vertices in $A$ are [*active*]{}, while the other vertices are [*inactive*]{}. The states of the edges belong to the set $\{$[*active*]{}, [*passive*]{}, [*used*]{}, [*just used*]{}$\}$. Initially the edges adjacent to the vertices in $A$ are set to active while all other are passive.

To each edge we associate a pointer to one of its endpoints and call it [*source*]{}. This variable is used at times when the water is flowing through the edge and it records the source of the current water flow. Initially, to each edge that originates from a vertex in $A$ we set the source to be the pointer to the vertex in $A$. All other edges have their source initially set to $0$.

There is additional variable $t$ that represents the time and is initially set to $0$.

Termination
-----------

The algorithm terminates if one of the following two conditions is satisfied:

1.  A vertex from $B$ becomes [*active*]{}. The variable $t$ contains the time it takes to reach this vertex along the shortest path $\hat \pi$, i.e. $t=F_1\left(\hat\pi\right)$. The label of the last vertex $\hat B$ on the path allows us to 