In this section, we present a single-source optimal-walks algorithm with respect to any linear combination of our optimality criteria. That is, given a temporal graph \(\mathcal {G} = (V,E,T, \beta)\), a cost function \(c \colon E \rightarrow \mathbb{N}\), and a source vertex *s*∈*V*, we compute optimal temporal walks with respect to any linear combination with *δ*_{1},…,*δ*_{7}∈*ℚ* from *s* to all vertices in the temporal graph (if they exist). To this end, we first apply Transformation 1 to \(\mathcal {G}\) to obtain an instantaneous temporal graph. Algorithm 1 then performs for each *t*∈[*T*] three main steps: GraphGeneration. Generate graph *G* which only contains the arcs present at time step *t* and add arcs from *s* to each vertex *v* in *G* that has been reached within the last *β*(*v*) time steps. ModDijkstra. Run a modified version of Dijkstra’s algorithm to compute for each *v* in *G* the optimal walk from *s* to *v* that arrives at time step *t* (if it exists). Update. Update a list storing information on optimal walks from *s* to each *v*∈*V*. More precisely, for each *v*∈*V* a list of tuples of arrival times and corresponding optimal values is updated.

Efficiently storing and accessing the value of an optimal walk from *s* to *v* that arrives at a certain time step *t* is the heart of the algorithm. We can maintain this information in *O*(|*E*|) time during a run of Algorithm 1 such that this information can be accessed in constant time, leading to the following theorem:

###
**Theorem 1**

With respect to any linear combination of the optimality criteria, optimal temporal walks from a source vertex *s* to each vertex in a temporal graph \(\mathcal {G} = (V,E,T, \beta)\) can be computed in *O*(|*V*|+|*E*| log|*E*|) time.

**Algorithm Details.** Let \(\mathcal {G}'\) be a temporal graph with a cost function \(c'\colon E \rightarrow \mathbb{N}\) and let *s*∈*V* be the source. We can apply Transformation 1 to \((\mathcal {G}',c')\) to obtain \((\mathcal {G} = (V,E,T, \beta),c,c_{\lambda },\text {ind},A)\) where \(\mathcal {G}\) is an instantaneous temporal graph. If \(\mathcal {G}'\) is already an instantaneous temporal graph, then we set *c*=*c*^{′}, *c*_{λ}≡0, ind≡1, and *A*≡0 as justified by Observation 2.

For given *δ*_{1},…,*δ*_{7}∈*ℚ*, Algorithm 1 for all *v*∈*V* now computes an optimal walk \(P=\left (\left (v_{i-1},v_{i},t_{i}\right)\right)_{i=1}^{k}=\left (e_{i}\right)_{i=1}^{k}\) from *s* to *v* with respect to

$$\begin{array}{*{20}l} \text{lin}^{\text{T}}(P)= &\delta_{1} \cdot(t_{k}) + \delta_{2}\cdot(-t_{1}) + \delta_{3}\cdot(t_{k} - t_{1}) + \delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ &+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{k-1} (t_{i+1} - t_{i} + A(v_{i+1})) \cdot \text{ind}(v_{i}). \end{array} $$

We have shown in Proposition 1 that an optimal walk with respect to lin^{T}(*P*) in \(\mathcal {G}\) directly corresponds to an optimal walk with respect to lin(*P*) in the original temporal graph \(\mathcal {G}'\).

For each vertex *v*∈*V*∖{*s*}, Algorithm 1 stores in opt(*v*) the value of an optimal walk from *s* to *v* and in *L*(*v*) a list of all relevant arrival times from *s* to *v* with their optimal values. In the beginning, opt(*v*)=*∞* and *L*(*v*) is an empty list (Line 1 in Algorithm 1). Then, for each time step *t* and each *v*∈*V*, Algorithm 1 computes the optimal walk from the source *s* to *v* that arrives in time step *t* (if it exists). Thus, Algorithm 1 performs for each *t*∈{1,…,*T*} the following steps: GraphGeneration. Generate a static graph *G* with GenerateGraph (Line 3 and Lines 9 to 19). This graph consists of the static graph *G*_{t}=(*V*_{t},*E*_{t}), that is, the static graph induced by all time-arcs with time stamp *t*, and the source vertex *s*.

The weight of an arc (*v*,*w*)∈*E*_{t} is set to *δ*_{4}·*c*_{λ}(*v*,*w*)+*δ*_{5}·*c*(*v*,*w*)+*δ*_{6}. If further *v*=*s*, then we have to add (*δ*_{2}+*δ*_{3})·(*T*−*t*) to take the departure time in *s* into account for the criteria *reverse-foremost* and *fastest*, see Line 12.

Additionally, non-existing arcs from *s* to each vertex *v*∈*V*_{t} are added if there exists a temporal walk from *s* to *v* that arrived not later than *β*(*v*) time steps ago. Let opt_{a} be the optimal value among all walks that arrive within the time interval [*t*−*β*(*v*),*t*] and let *a* be the corresponding arrival time in *v*. Additionally, the minimum waiting time *A*(*v*) plus the additional waiting time (*t*−*a*) in *v* has to be taken into account if ind(*v*)=1. Hence, the weight of arc (*s*,*v*) is set to opt_{a}+*δ*_{7}·ind(*v*)·(*t*−*a*+*A*(*v*)), see Line 18. Let *E*_{r} be the set of these additional arcs. Then, *G*=(*V*_{t}∪{*s*},*E*_{t}∪*E*_{r},*d*_{t},*d*_{r}). ModDijkstra. Run a modified Dijkstra Algorithm on *G* with modDijkstra (Line 4 and Lines 20 to 31). Instead of computing a shortest walk (using the original Dijkstra Algorithm) in *G*, compute a shortest walk among all walks that end in an arc of *E*_{t}. This represents a temporal walk that arrives in time step *t* with optimal value. The function modDijkstra returns the set *V*^{′} of vertices that can be reached within *G* via an arc in *E*_{t} and the function \(\text {opt}_{t} \colon V' \rightarrow \mathbb{N}\) that maps each vertex *v*∈*V*^{′} to its optimal value of a walk from *s* to *v* arriving exactly at time *t*. Update. For each *v*∈*V*^{′}, set the optimum opt(*v*) to the minimum of its current value and the optimal value of a newly computed walk, that is, opt(*v*):= min{opt(*v*),*δ*_{1}·*t*+*δ*_{3}·(*t*−*T*)+opt_{t}(*v*)} (Line 6). Herein, we have to add the arrival time *t* that has not been taken into account in the calculation of the optimal value because it is the same for all walks found at time step *t*. Add the tuple (opt_{t}(*v*),*t*) to list *L*(*v*) (Line 7).

After the **Update** step for time step *t*, the list *L*(*v*) contains all tuples (opt_{ar},ar) such that there exists a walk from *s* to *v* that arrives at time ar∈[*t*−*β*(*v*),*t*] with its optimal cost value opt_{ar}. We want to have constant-time access to the optimal value of a walk that arrives in *v* within time interval [*t*−*β*(*v*),*t*]. This can be achieved by deleting tuples from list *L*(*v*) that are *redundant*, that is these tuples are not meaningful for the correct computation of optimal walks. Let

$$L(v)=[(\text{opt}_{a_{1}},a_{1}), \ldots,(\text{opt}_{a_{k}},a_{k})]$$

be such a list for a time step *t* with *t*−*β*(*v*)≤*a*_{1}<…<*a*_{k}≤*t*. A tuple (opt_{ar},ar) is redundant if there exists a tuple with an arrival time greater than ar such that its optimal value is smaller than opt_{ar} plus the additional waiting time. This is shown with the following lemma:

###
**Lemma 1**

For a time step *t*∈{1,…,*T*} and a vertex *v*∈*V*, if there are two tuples \((\text {opt}_{a_{i}},a_{i}),(\text {opt}_{a_{j}},a_{j}) \in L(v)\) with *a*_{i}<*a*_{j} and

$$\text{opt}_{a_{j}} \leq \text{opt}_{a_{i}} + \delta_{7} \cdot \text{ind}(v) \cdot (a_{j}-a_{i}),$$

then \((\text {opt}_{a_{i}},a_{i})\) is redundant and can be removed from *L*(*v*).

###
*Proof*

After all time-arcs with time stamp *t* have been processed, Algorithm 1 only considers time-arcs with time stamp *t*^{′}>*t*. In the generated graph *G* (Line 3), the algorithm adds an arc from *s* to \(\phantom {\dot {i}\!}v\in V_{t^{\prime }}\) if a walk from *s* arrives in *v* within [*t*^{′}−*β*(*v*),*t*^{′}]. If *a*_{i}∈[*t*^{′}−*β*(*v*),*t*^{′}], then *a*_{j}∈[*t*^{′}−*β*(*v*),*t*^{′}] because *a*_{i}<*a*_{j}<*t*^{′}. Furthermore, let (opt,*a*) be the optimal value and the arrival time of a walk from *s* to *v* that arrives within time interval [*t*^{′}−*β*(*v*),*t*^{′}] that minimizes

$$\text{opt} + \delta_{7} \cdot \text{ind}(v) (t' - a + A(v)).$$

Then, the weight of the arc (*s*,*v*) is set to this value. Since *a*_{i}<*a*_{j}∈[*t*^{′}−*β*(*v*),*t*^{′}] and \(\text {opt}_{a_{i}} + \delta _{7} \cdot \text {ind}(v) \cdot (a_{j}-a_{i}) \geq \text {opt}_{a_{j}}\), we know that

$$\text{opt}_{a_{j}} + \delta_{7} \cdot \text{ind}(v) (t' - a_{j} + A(v))\leq \text{opt}_{a_{i}} + \delta_{7} \cdot \text{ind}(v) (t' - a_{i} + A(v)).$$

Hence, the tuple \((\text {opt}_{a_{i}},{a_{i}})\) is not needed in the list *L*(*v*) at time step *t* and can be removed. □

If *L*(*v*) does not contain any redundant tuples, then it also holds that

$$\text{opt}_{a_{1}} + \delta_{7} \cdot \text{ind}(v) \cdot (a_{2}-a_{1})< \cdots < \text{opt}_{a_{k}}.$$

Hence, \(\phantom {\dot {i}\!}(a_{1}, \text {opt}_{a_{1}})\) contains the optimal value and arrival time of a walk that arrives within time interval [*t*−*β*(*v*),*t*] and minimizes opt+*δ*_{7}·ind(*v*)(*t*^{′}−*a*+*A*(*v*)). It follows that finding opt= min{opt_{a}∣(opt_{a},*a*)∈*L*(*v*)} in Line 18 takes constant time. The deletion of redundant tuples takes *O*(|*E*|) time during the whole run of Algorithm 1. With these considerations at hand, we can derive the following lemma.

###
**Lemma 2**

Algorithm 1 runs in *O*(|*V*|+|*E*| log|*E*|) time.

###
*Proof*

The initialization in Algorithm 1 can be done in *O*(|*V*|) time. Furthermore, the time-arcs have to be sorted by time stamps which takes *O*(|*E*| log|*E*|) time. Then, for each time step *t*∈[*T*], Algorithm 1 generates in *O*(|*E*_{t}|+|*V*_{t}|) time a static directed graph *G*=(*V*_{t}∪{*s*},*E*_{t}∪*E*_{r}) with *O*(|*V*_{t}|) vertices and *O*(|*E*_{t}|+|*V*_{t}|) arcs.

For each generated graph *G*, modDijkstra is executed in *O*(|*E*_{t}| log|*E*_{t}|) time. The updates of opt and *L* afterwards run in *O*(|*V*_{t}|) time. Note that |*V*_{t}| is the number of vertices that have at least one in-going or out-going time-arc at time step *t*. Consequently, it holds that |*V*_{t}|≤2|*E*_{t}|.

Due to the sorting of *L*(*v*), maintaining these lists in Lines 15 and 7 takes *O*(|*E*|) time during the whole run of the algorithm as shown Lemma 1. In the list *L*(*v*), we delete at most as many elements as there are time-arcs in the temporal graph. Recall that if (opt_{a},*a*)∈*L*(*v*), then there exists a time-arc (*w*,*v*,*a*)∈*E*.

We can analyze the running time by

$$\begin{array}{*{20}l} &O\big(|V| + |E| + \sum_{t=1}^{T} (|E_{t}|) + (|V_{t}| \log |V_{t}|) \big)\\ = ~&O\big(|V| + |E| + \sum_{t=1}^{T} (|E_{t}|) + (|E_{t}| \log |E_{t}|) \big)\\ = ~&O\big(|V| + |E| + \sum_{t=1}^{T} |E_{t}| \log |E_{t}| \big)\\ \subseteq ~&O\big(|V| + |E| \log |E| \big). \end{array} $$

Hence, Algorithm 1 runs in *O*(|*V*|+|*E*| log|*E*|) time. □

Next, we show the correctness of Algorithm 1. We prove that for every time step *t* and for every vertex *v*, Algorithm 1 computes an optimal walk from *s* to *v* that arrives at time step *t* (if it exists).

###
**Lemma 3**

For a time step *t*∈[*T*] and a vertex *v*∈*V*, Algorithm 1 computes the optimal value of a temporal walk from *s* to *v* that arrives exactly in time step *t*.

###
*Proof*

The proof is by induction on the time step *t*∈{1,…,*T*}.

In the beginning, *L*(*v*) is empty. For *t*=1, the algorithm generates a graph *G*=(*V*_{1}∪{*s*},*E*_{1}). For all arcs (*s*,*w*)∈*E*_{1}, the weights are set to

$$d_{1}(s,w) := (\delta_{2}+ \delta_{3}) \cdot(T-1) + \delta_{4} \cdot c_{\lambda}((v,w,1))+ \delta_{5} \cdot c((v,w,1)) + \delta_{6};$$

for the other arcs (*v*,*w*)∈*E*_{1} the weights are set to

$$d_{1}(v,w)=\delta_{4} \cdot c_{\lambda}(v,w)+ \delta_{5} \cdot c((v,w,1)) + \delta_{6}.$$

Note that if there is an optimal temporal walk arriving in time step 1, then there also exists an optimal temporal walk arriving at time step 1. Now if there is an optimal walk \(P=\left (\left (v_{i-1},v_{i},1\right)\right)^{k}_{i=1}=\left (e_{i}\right)^{k}_{i=1}\) from *s* to a vertex *v*∈*V* that arrives exactly in time step 1, then there exists a path \(P'=\left (\left (v_{i-1},v_{i}\right)\right)^{k}_{i=1}=\left (a_{i}\right)^{k}_{i=1}\) from *s* to *v* in *G* with value

$$\begin{array}{*{20}l} \sum_{i=1}^{k} d_{t}(a_{i}) &= (\delta_{2}+ \delta_{3}) \cdot(T-1) + \sum_{i=1}^{k} \delta_{4} \cdot c_{\lambda}(v_{i-1},v_{i})+ \delta_{5} \cdot c(v_{i-1},v_{i}) + \delta_{6}\\ &= \text{opt}_{1}(v). \end{array} $$

Algorithm 1 finds in modDijkstra the path *P*^{′}, adds (opt_{1}(*v*),1) to *L*(*v*) and sets

$$\begin{array}{*{20}l} \text{opt}(v) := ~&\delta_{1} \cdot 1 - \delta_{2} \cdot T + \delta_{3} \cdot (1-T) + \text{opt}_{1}(v)\\ = ~&\delta_{1} \cdot 1 - \delta_{2} \cdot T + \delta_{3} \cdot (1-T) + (\delta_{2}+ \delta_{3}) \cdot(T-1) + \sum_{i=1}^{k} \delta_{4} \cdot c_{\lambda}(v_{i-1},v_{i})\\ &+ \delta_{5} \cdot c(v_{i-1},v_{i}) + \delta_{6} \cdot k\\ = ~&\delta_{1} \cdot 1 - \delta_{2}\cdot 1 + \delta_{3}\cdot 0 + \delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ &+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{k-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i})\\ = ~&\text{lin}^{\text{T}}(P). \end{array} $$

Note that *A*(*v*_{i})=0 for *i*∈[*k*−1] by Transformation 1 in time step 1. If there exists an optimal path *P*^{∗} in *G*, then this directly translates to the existence of a temporal path *P*^{′} that arrives also in time step 1 with a smaller optimal value than *P*, contradicting the assumption that *P* is optimal.

Now, let us assume that for all time steps *t*^{′}∈{1,…,*t*} Algorithm 1 computed the optimal value opt of a walk from *s* to *v*∈*V* that arrives exactly in time step *t*^{′} and added (opt−*δ*_{1}·*t*^{′}+*δ*_{2}·*T*−*δ*_{3}·(*t*^{′}−*T*),*t*^{′}) to *L*(*v*). If for time step *t*+1 a vertex *v*∈*V* has no in-going time-arc with time step *t*+1, then there cannot exist a temporal walk from *s* to *v* that arrives exactly in time step *t*+1. Thus, only vertices in *V*_{t+1} are candidates for a temporal walk that arrives exactly in time step *t*+1.

Let *v*∈*V*_{t+1} be a vertex such that there is a temporal walk from *s* to *v* that arrives exactly in time step *t*+1. Let \(P=\left (\left (v_{i-1},v_{i},1\right)\right)^{k}_{i=1}=\left (e_{i}\right)^{k}_{i=1}\) be an optimal walk from *s* to *v* that arrives exactly in time step *t*+1 with the optimal value

$$\begin{array}{*{20}l} \text{lin}^{\text{T}}(P) &= \delta_{1} \cdot t_{1} - \delta_{2}\cdot t_{k} + \delta_{3}\cdot (t_{k} - t_{1}) + \delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ &~~~+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{k-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i}). \end{array} $$

Assume towards a contradiction that Algorithm 1 does not find a walk from *s* to *v* with optimal value lin^{T}(*P*).

First consider the case that *t*_{i}=*t*+1 for all *i*∈[*k*], that is, all time-arcs of the temporal walk *P* have time stamp *t*+1. Then, we can assume that *P* is a temporal path. Hence there exists a path \(P'=\left (\left (v_{i-1},v_{i}\right)\right)^{k}_{i=1}=\left (a_{i}\right)^{k}_{i=1}\) from *s* to *v* in *G*_{t+1} and therefore in *G* with optimal value

$$\begin{array}{*{20}l} \sum_{i=1}^{k} d_{t}(a_{i}) &= (\delta_{2}+ \delta_{3}) \cdot(T-(t+1)) + \sum_{i=1}^{k} \delta_{4} \cdot c_{\lambda}(v_{i-1},v_{i}) + \delta_{5} \cdot c(v_{i-1},v_{i}) + \delta_{6}\\ &= \text{opt}_{t+1}(v). \end{array} $$

Algorithm 1 finds in modDijkstra the path *P*^{′}, adds (opt_{t+1}(*v*),*t*+1) to *L*(*v*), and updates opt(*v*) to the minimum of opt(*v*) and

$$\begin{array}{*{20}l} &\delta_{1} \cdot (t+1) - \delta_{2} \cdot T + \delta_{3} \cdot (t+1-T) + \text{opt}_{t+1}(v)\\ = ~&\delta_{1} \cdot (t+1) - \delta_{2} \cdot T + \delta_{3} \cdot (t+1-T) + (\delta_{2}+ \delta_{3}) \cdot(T-(t+1)) \\ &+ \sum_{i=1}^{k} \delta_{4} \cdot c_{\lambda}(v_{i-1},v_{i}) + \delta_{5} \cdot c(v_{i-1},v_{i}) + \delta_{6} \cdot k\\ = ~&\delta_{1} \cdot t_{1} - \delta_{2}\cdot t_{k} + \delta_{3}\cdot (t_{k} - t_{1}) + \delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ &+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{k-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i})\\ = ~&\text{lin}^{\text{T}}(P). \end{array} $$

Note again that *A*(*v*_{i})=0 for *i*∈[*k*−1] if *t*_{i−1}=*t*_{i} by Transformation 1. Hence, we find a walk from *s* to *v* at time step *t*+1 with optimal value lin^{T}(*P*), contradicting our assumption.

Now assume for *P* that there exists an *ℓ*∈{1,…,*k*−1} such that for *j*∈[*ℓ*] it holds that *t*_{j}<*t*+1 and for *j*^{′}∈{*i*+1,…,*k*} it holds that \(\phantom {\dot {i}\!}t_{j^{\prime }} = t+1\). The temporal walk \(P_{\ell }= \left (\left (v_{i-1},v_{i},t_{i}\right)\right)^{\ell }_{i=1}=\left (e_{i}\right)^{k}_{i=1}\) is an optimal subwalk from *s* to *v*_{ℓ} that arrives exactly in time step *t*_{ℓ}, otherwise *P* is not optimal because it could be improved by replacing *P*_{ℓ}. The subwalk *P*_{ℓ} has an optimal value

$$\begin{array}{*{20}l} \text{lin}^{\text{T}}(P_{\ell}) = ~& \delta_{1} \cdot t_{1} - \delta_{2}\cdot t_{\ell} + \delta_{3}\cdot (t_{\ell} - t_{1}) + \delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ & +\delta_{5}\cdot \sum_{i=1}^{\ell} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{\ell-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i}). \end{array} $$

Then

$$\begin{array}{*{20}l} \text{opt}_{t_{\ell}}(v_{\ell}) = ~&\text{opt}_{P_{\ell}} - \delta_{1} \cdot t_{\ell} + \delta_{2} \cdot T - \delta_{3} \cdot (t_{\ell} -T)\\ = ~&(\delta_{2}+ \delta_{3}) \cdot(T-t_{\ell}) + \delta_{4}\cdot \sum_{i=1}^{\ell} c_{\lambda}(e_{i}) \\ &+\delta_{5}\cdot \sum_{i=1}^{\ell} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{\ell-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i}). \end{array} $$

By our induction hypothesis, the tuple \((\text {opt}_{t_{\ell }}(v_{\ell }),t_{\ell })\) was added to *L*(*v*_{ℓ}). If the tuple \((\text {opt}_{t_{\ell }}(v_{\ell }),t_{\ell })\) is not in *L*(*v*_{ℓ}) in time step *t*+1, then due to Lemma 1 there must be another tuple \((\text {opt}_{\hat t}(v_{\ell }),\hat t)\) in *L*(*v*_{ℓ}) with \(t_{\ell } < \hat t < t+1 < t_{\ell } + \beta (v_{\ell }) \leq \hat t + \beta (v_{\ell })\) and

$$\text{opt}_{t_{\ell}}(v_{\ell}) + \delta_{7} \cdot \text{ind}(v_{\ell}) (t+1 - t_{\ell} + A(v_{\ell})) = \text{opt}_{\hat t}(v_{\ell}) + \delta_{7} \cdot \text{ind}(v_{\ell}) (t+1 - \hat t + A(v_{\ell})).$$

Otherwise *P* is not optimal because it could be improved by replacing *P*_{ℓ} by the temporal walk represented by \((\text {opt}_{\hat t}(v_{\ell }),\hat t)\).

Now consider the generated graph *G*=(*V*_{t+1}∪{*s*},*E*_{t+1}∪*E*_{r}). The arc sequence \(P_{t+1}=\left (\left (v_{i-1},v_{i}\right)\right)^{k}_{i=\ell +1}=\left (a_{i}\right)^{k}_{i=\ell +1}\) is a path in *G*_{t+1}=(*V*_{t+1},*E*_{t+1}) and, thus, contained in *G*. The arc *a*_{ℓ}=(*s*,*v*_{ℓ}) is contained in *E*_{r} with weight

$$d_{r}(s,v_{\ell}) = \text{opt}_{t_{\ell}}(v_{\ell}) + (t+1 - t_{\ell} + A(v_{\ell})) \cdot \text{ind}(v_{\ell}).$$

Thus, there is a walk from *s* to *v* in *G* and modDijkstra on *G* returns the vertex *v* because *a*_{k}∈*E*_{t+1} with the optimal value

$$\begin{array}{*{20}l} &d_{r}(a_{\ell}) + \sum_{i=\ell+1}^{k} d_{t}(a_{i}) \\ = ~&\text{opt}_{t_{\ell}}(v_{i}) + \text{ind}(v_{\ell})\cdot (t+1 - t_{\ell} + A(v_{\ell})) \\ &+ \sum_{i=\ell+1}^{k} \delta_{4} \cdot c_{\lambda}(v_{i-1},v_{i},t+1)+ \delta_{5} \cdot c(v_{i-1},v_{i},t+1) + \delta_{6}\\ = ~&(\delta_{2}+ \delta_{3}) \cdot(T-t_{\ell}) + \sum_{i=1}^{\ell} \big (\delta_{4}\cdot c_{\lambda}(e_{i}) +\delta_{5}\cdot c(e_{i}) + \delta_{6} \big)\\ &+ \delta_{7} \cdot \sum_{i=1}^{\ell-1} \text{ind}(v_{i}) \cdot (t_{i+1} - t_{i} + A(v_{i})) \\ &+ \text{ind}(v_{\ell})\cdot (t+1 - t_{\ell} + A(v_{\ell}))\\ &+\sum_{i=\ell+1}^{k} \big (\delta_{4} \cdot c_{\lambda}(v_{i-1},v_{i})+ \delta_{5} \cdot c(v_{i-1},v_{i}) + \delta_{6} \big) \\ = ~&(\delta_{2}+ \delta_{3}) \cdot(T-t_{\ell}) + \delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ &+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{\ell} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i})\\ = ~&(\delta_{2}+ \delta_{3}) \cdot(T-t_{\ell}) + \delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ &+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{k-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i})\\ = ~&\text{opt}_{t+1}(v). \end{array} $$

Note that by Transformation 1*A*(*v*_{i})=0 for *i*∈[*ℓ*+1,*k*−1] if *t*_{i−1}=*t*_{i}. Consequently, the tuple (opt_{t+1}(*v*),*t*+1) is added to *L*(*v*) and opt(*v*) is set to the minimum of its current value and

$$\begin{array}{*{20}l} &\delta_{1} \cdot (t+1) -\delta_{2} \cdot T + \delta_{3} (t+1 -T) + \text{opt}_{t+1}(v)\\ = ~&\delta_{1} \cdot (t+1) -\delta_{2} \cdot T + \delta_{3} (t+1 -T)\\ &+(\delta_{2}+ \delta_{3}) \cdot(T-t_{1}) + \delta_{4} \cdot \sum_{i=1}^{k} c_{\lambda}(e_{i})\\ &+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{k-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i}) \end{array} $$

$$\begin{array}{*{20}l} = ~& \delta \cdot (t+1) + \delta_{2} \cdot (t_{k}) + \delta_{3} (t+1 -t_{1}) +\delta_{4}\cdot \sum_{i=1}^{k} c_{\lambda}(e_{i}) \\ &+\delta_{5}\cdot \sum_{i=1}^{k} c(e_{i}) + \delta_{6}\cdot k + \delta_{7} \cdot \sum_{i=1}^{k-1} (t_{i+1} - t_{i} + A(v_{i})) \cdot \text{ind}(v_{i})\\ = ~&\text{lin}^{\text{T}}(P). \end{array} $$

This is a contradiction to our assumption.

Lastly, observe that the algorithm only computes temporal walks that are contained in *G* as it only uses arcs from *G*_{t} which all correspond to temporal walks in *G* (single arcs or longer walks starting in *s*). Thus, for *t*∈{1,…,*T*}, Algorithm 1 computes an optimal temporal walk from *s* to *v*∈*V* that arrives exactly in time step *t*. □

Based on this statement, we can finally prove the correctness of Algorithm 1. This concludes the proof of Theorem 1.

###
**Lemma 4**

Algorithm 1 computes *optimal* walks from a given source vertex *s* to all vertices.

###
*Proof*

Let \(P=\left (\left (v_{i-1},v_{i},1\right)\right)^{k}_{i=1}=\left (e_{i}\right)^{k}_{i=1}\) be a walk with minimum lin^{T}(*P*) among all temporal walks from *s* to a vertex *v*. The walk *P* is also an optimal walk from *s* to *v* that arrives exactly in time step *t*_{k}. This is computed by Algorithm 1 in time step *t*_{k} as shown in Lemma 3. □