Abstract 1 Introduction 2 Preliminaries 3 Foremost paths 4 Fastest paths 5 Shortest paths 6 Conclusion References

Foremost, Fastest, Shortest: Temporal Graph Realization Under Various Path Metrics

Justine Cauvi ORCID École Normale Supérieure de Lyon, France
Inria, DI ENS, Paris, France
Nils Morawietz ORCID LaBRI, Université de Bordeaux, Talence, France
Institute of Computer Science, Friedrich Schiller University Jena, Germany
Laurent Viennot ORCID Inria, DI ENS, Paris, France
Abstract

In this work, we follow the current trend on temporal graph realization, where one is given a property P and the goal is to determine whether there is a temporal graph, that is, a graph where the edge set changes over time, with property P. We consider the problems where the given property P is a prescribed matrix for the duration, length, or earliest arrival time of pairwise temporal paths. This means that we are given a matrix D and ask whether there is a temporal graph such that for any ordered pair of vertices (s,t), Ds,t equals the duration (length, or earliest arrival time, respectively) of any temporal path from s to t minimizing that specific temporal path metric. For shortest and earliest arrival temporal paths, we are the first to consider these problems as far as we know. We analyze these problems for many settings such as: strict and non-strict paths, periodic and non-periodic temporal graphs, and limited number of labels per edge (limited number of occurrences per edge over time). In contrast to all other path metrics, we show that for the earliest arrival times, we can achieve polynomial-time algorithms in periodic and non-periodic temporal graphs and for strict and and non-strict paths. However, the problem becomes NP-hard when the matrix does not contain a single integer but a set or range of possible allowed values. As we show, the problem can still be solved efficiently in this scenario, when the number of entries with more than one value is small, that is, we develop an FPT-algorithm for the number of such entries. For the setting of fastest paths, we achieve new hardness results that answers an open question by Klobas, Mertzios, Molter, and Spirakis [Theor. Comput. Sci. ’25] about the parameterized complexity of the problem with respect to the vertex cover number and significantly improves over a previous hardness result for the feedback vertex set number. When considering shortest paths, we show that the periodic versions are polynomial-time solvable whereas the non-periodic versions become NP-hard.

Keywords and phrases:
network design, temporal paths, foremost paths, fastest paths, shortest paths, non-strict paths, periodic temporal graphs
Copyright and License:
[Uncaptioned image] © Justine Cauvi, Nils Morawietz, and Laurent Viennot; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation → Design and analysis of algorithms
Related Version:
Full Version: https://arxiv.org/abs/2510.01702
Funding:
Supported by the French ANR, projects ANR-22-CE48-0001 (TEMPOGRAL) and ANR-24-CE48-4377 (GODASse).
Editors:
Meena Mahajan, Florin Manea, Annabelle McIver, and Nguyễn Kim Thắng

Due to space constraints, proofs of results marked with ⋆ are (partially) deferred to the full version accessible at https://arxiv.org/abs/2510.01702.

1 Introduction

Graph realization problems have been studied since the 1960s and consists of finding a static graph that satisfies a desired property P or answering that no such graph exists. The earliest example of such a problem is the case of degree sequence realization, where one is given a non-decreasing sequence (d1,…,dn) of natural numbers, and one asks whether there is an undirected graph G with vertex set {1,…,n}, such that vertex i has degree exactly di. This problem was introduced by Erdős and Gallai [9] and generalizations of it remain the object of active study (see, e.g., [2] when ranges are given for each degree). In another early graph realization problem by Hakimi and Yau [13], one is given an n×n distance matrix D and asks whether there is a static graph on n vertices where, for each ordered pair (i,j) of vertices, the shortest path from i to j has length exactly Di,j. Since the introduction of these early problems, graph realization problems were considered in many variations and for many other desirable properties to realize. Recently motivated by the realization problem for distance matrices on static graphs, Klobas, Mertzios, Molter and Spirakis [16] lifted graph realization problems to the realm of temporal graphs. Here, a temporal graph 𝒢 is a finite sequence (G1,…,GL) of static graphs that are all defined over the same vertex set. Temporal graphs are a valuable tool to model and analyze the behavior of real world dynamic networks [4]. In the problem introduced by Klobas et al. [16], the goal is to decide whether a desired property is fulfilled by some temporal graph. They introduced the following problem:

Fastest-path TGR:

Input: An n×n distance matrix D.

Question: Is there a temporal graph 𝒢 with n vertices such that for any ordered pair (s,t) of vertices, the fastest temporal path from s to t has duration Ds,t?

Recall that a (strict) temporal path can start at any time step and is allowed to traverse at most one edge per time step, and its duration is the difference between the starting time and the arrival time, and that a fastest temporal path is a temporal path with minimum duration (see Section 2). More precisely, the authors considered this problem111They analyzed the problem under the name Simple (Periodic) Temporal Graph Realization. where only a single label per edge is allowed and where the temporal graph is periodic, that is, where the same edges repeat every Δ time steps for some period Δ>0. They showed that the this version of the problem is NP-hard and they exhibited an FPT algorithm parameterized by the feedback edge number of the underlying graph, that is, the uniquely defined graph that contains an edge {s,t} if and only if Ds,t=Dt,s=1. In contrast, they showed that this version of the problem is W[1]-hard when parameterized by the feedback vertex set number of the underlying graph. Erlebach, Morawietz and Wolf [11] generalized the problem by allowing each edge to appear up to ℓ times per period and proved that this remains NP-hard even on underlying graphs that are trees for ℓ=5. In [19], the authors studied the problem where upper bounds on the fastest paths are given and the underlying graph is a tree. This was further considered for directed graphs by Meusel, Müller-Hannemann and Reinhardt [21]. Further recent papers on temporal graph realization include: designing a temporal graph for which the fastest path should not have duration more than α times the real distance [20], designing a temporal graph which should have a prescribed reachability relation between the vertices [10], and designing a temporal graph for which all pairs of agents can pairwise reach each other via strict temporal paths, with one label per edge, while the degree sequence of the underlying graph is prescribed [3]. It is worth mentioning that Göbel, Cerdeira and Veldman [12] considered a connectivity problem that can also be seen as a temporal graph realization problem. All these problems are motivated both from a design perspective, where we aim to design a network with a desired behavior, or from a verification perspective, where we want to verify that the behavior of our network is correct or at least plausible. From the perspective of temporal network design problems, the field is even more vibrant (see, e.g., [14, 17, 18, 8, 23, 7, 1, 15]).

Our Results.

In this work, we extend the previous work on Fastest-path TGR to the non-strict case (that is, where arbitrary many edges per time step can be traversed). Furthermore, we consider the other most frequently used temporal path metrics Foremost and Shortest (formally defined in Section 2). Roughly speaking, Foremost-path TGR requires that the earliest arrival time at t, minimized over all temporal s⁢t-paths, is equal to Ds,t for each vertex pair (s,t), whereas Shortest-path TGR requires that the number of edges, minimized over all temporal s⁢t-paths, is equal to Ds,t for each vertex pair (s,t). Our main results are as follows:

  1. 1.

    In Section 3 we show that all considered versions (strict/non-strict, periodic/non-periodic) of Foremost-path TGR are polynomial-time solvable if we are allowed to put an arbitrary number of labels on each edge. This is surprising, as almost all other previously mentioned temporal graph realization problems turn out to be NP-hard (with one exception [3]). In particular, we show that all our algorithms produce a labeling with at most n2 time labels in total, if dealing with a realizable instance. This is asymptotically tight as some realizable matrices do require Ω⁢(n2) time labels.

  2. 2.

    To show the limitations of the tractability, we also show in Section 3 that Foremost-path TGR becomes NP-hard if (i) we are only allowed to assign one label per edge or (ii) the matrix D contains more than one entry for each vertex pair, and we are to choose which of these possible values we want to realize. For the latter problem version, we present a single exponential FPT-algorithm when parameterized by the number of entries in D that have more than one possible value.

  3. 3.

    In Section 4 we consider Fastest-path TGR. Among other results, we answer open questions by Klobas et al. [16] and Erlebach et al. [11] about the parameterized complexity of the problem for the vertex cover number. We show that the problem is W[1]-hard when parameterized by this parameter plus the largest entry in the matrix. This result improves significantly over the previous known parameterized hardness result for the feedback vertex set number; in terms of the parameter, the construction, and the length of the proof.

  4. 4.

    In Section 5 we consider Shortest-path TGR and show that the problem is NP-hard for both the strict and the non-strict case, but becomes trivial when considering a periodic temporal graph.

Finally, in Section 6, we conclude with some open questions for future work.

2 Preliminaries

For natural numbers 1≤i≤j, we let [i,j]:={i,i+1,…,j} and we define [j]:=[1,j].

(Static) graphs.

An (undirected) graph G=(V,E) is defined by its vertex set V and its edge set E⊆(V2). Any pair {u,v}∈E is called an edge between vertices u and v. We also say that u and v are neighbors when {u,v}∈E. For a vertex set S⊆V, we define the subgraph of G induced by S as G⁢[S]:=(S,E∩(S2)). A graph H=(V′,E′) is a subgraph of G if V′⊆V and E′⊆E. A u⁢v-walk is a sequence P=(v0=u,v1,…,vk=v) of vertices such that {vi−1,vi} is an edge for every i∈[k]. We then say that P is a walk from u to v in G. Such a walk is called a path if the vertices v0,…,vk are pairwise distinct.

Temporal graphs.

A temporal graph is defined by a pair 𝒢=(G,λ) where G=(V,E) is a graph, and λ:E→2ℕ>0 is a labeling that associates to each edge e∈E the set λ⁢(e) of (positive) times when e appears. The graph G is called the underlying graph of 𝒢 and the labeling λ is called the time labeling of 𝒢. When 𝒢 is clear from the context, we let n=|V| denote the number of vertices of 𝒢. A time-edge is a pair ({u,v},τ) such that {u,v}∈E and τ∈λ⁢({u,v}). Its appearance time is τ. Given a time label τ∈ℕ>0, we define the set Eτ={e∈E:τ∈λ⁢(e)} of edges appearing at time τ, and call Gτ=(V,Eτ) the snapshot of 𝒢 at time τ. The size of a temporal graph can be measured by its number ∑e∈E|λ⁢(e)| of time labels. A temporal graph is said to be Δ-periodic if each edge appears periodically with period Δ∈ℕ>0, that is τ∈λ⁢(e) if and only if τmodΔ∈λ⁢(e). Such a temporal graph is represented by its list of time-edges up to time Δ. In the following, we always assume that the vertices of a temporal graph 𝒢 are numbered from 1 to n. We assume without loss of generality that its vertex set is V=[n]. We let 𝒯⁢𝒢 denote the set of all such temporal graphs.

Temporal paths.

A strict (respectively non-strict) temporal u⁢v-walk is a walk P=(v0=u,v1,…,vk=v) in G with associated time labels (τ1,…,τk) such that τi∈λ⁢({vi−1,vi}) for each i∈[k] and τ1<⋯<τk (respectively τ1≤⋯≤τk). Equivalently, a temporal walk can be defined as the sequence of time-edges ({v0,v1},τ1),…,({vk−1,vk},τk) satisfying τ1<⋯<τk (respectively τ1≤⋯≤τk). Moreover, P has length k, departure time τ1, arrival time τk, and duration τk−τ1+1 (number of time steps spanned). A temporal u⁢v-walk is called a temporal u⁢v-path if the vertices v0,…,vk are pairwise distinct. Note that a strict (respectively non-strict) temporal walk can always be transformed into a strict (respectively non-strict) temporal path by removing loops, and this can only reduce length, arrival time and duration. By default, we consider strict temporal paths, and simply call them temporal paths. We specify non-strict for non-strict temporal paths.

Temporal path metrics.

Classically, a temporal u⁢v-path is said to be shortest, foremost, or fastest if it has minimum number of edges, minimum arrival time, or minimum duration, respectively among all temporal u⁢v-paths. These notions indeed define some kinds of metrics that we now formalize. A distance matrix D is any matrix of size n×n with values in ℕ∪{∞} and that satisfies the following very loose notion of metric: Du⁢v=0 if and only if u=v, for all u,v∈[n]. It is not assumed that D satisfies any other specific properties. In particular, D may violate the triangle inequality. A temporal path metric is defined as a function M that associates a distance matrix M⁢(𝒢) to any temporal graph 𝒢∈𝒯⁢𝒢. Consider for example, a cost function C that associates a positive cost in ℕ>0 to any temporal path given as a sequence of time-edges (independently of any temporal graph). It defines a temporal path metric by associating to any temporal graph 𝒢∈𝒯⁢𝒢 the matrix C⁢(𝒢) (respectively NS-⁢C⁢(𝒢)) such that C⁢(𝒢)u⁢v (respectively NS-⁢C⁢(𝒢)u⁢v) is the minimum cost of a strict (respectively non-strict) temporal u⁢v-path in 𝒢. We define C⁢(𝒢)u⁢v:=∞ (respectively NS-⁢C⁢(𝒢)u⁢v:=∞) if no strict (respectively non-strict) temporal u⁢v-path exists and C⁢(𝒢)u⁢v:=0 (respectively NS-⁢C⁢(𝒢)u⁢v:=0) if u=v. The foremost, fastest, and shortest notions are indeed associated to the following cost functions: arrival time, duration, and length, respectively. We let Foremost, Fastest, and Shortest denote the corresponding temporal path metrics, respectively. We also let NS−Foremost, NS−Fastest, and NS−Shortest denote the respective variants for non-strict temporal paths. For example, given a temporal graph 𝒢, and two vertices u,v in 𝒢, Foremost(𝒢)u⁢v is the earliest arrival time of a strict temporal u⁢v-path in 𝒢.

Temporal graph realization.

Given an integer n, the temporal graph realization problem consists of finding a temporal graph with n vertices that satisfies a given property. We assume that this property can be expressed as an input sequence I∈{0,1}∗ of bits, given that the vertices of the temporal graph are 1,…,n. More precisely, we define a predicate P as a binary relation between the set 𝒯⁢𝒢 of all temporal graphs and the set {0,1}∗ of all bit sequences, that is P is a subset of 𝒯⁢𝒢×{0,1}∗. We then say that a temporal graph 𝒢 satisfies a sequence I of bits for P if (𝒢,I)∈P. We equivalently say that P⁢(𝒢,I) is satisfied, or that 𝒢 is a realization of I for P. As a simple example, the lifetime of a temporal graph can be tested by the predicate P⁢(𝒢,Λ):=max⁡(∪e∈Eλ⁢(e))=Λ where 𝒢=(G,λ) and Λ encodes an integer (that we denote also by Λ with a slight abuse of notation). That is P⁢(𝒢,Λ) is satisfied when Λ is the last appearance time of a time-edge of 𝒢. Given a predicate P we thus define the following (very general) problem.

P Temporal Graph Realization (P TGR):

Input: A number n and a sequence I of bits.

Question: Is there a temporal graph 𝒢 with n vertices such that P⁢(𝒢,I) is satisfied?

This paper focuses on temporal path metric realization. More precisely, considering a temporal path metric M∈{Foremost,Fastest,Shortest,NS−Foremost,NS−Fastest, NS−Shortest}, we define the M-temporal-path-metric predicate, or M-path for short, as P⁢(𝒢,I):=M⁢(𝒢)=D where the sequence I of bits encodes an n×n distance matrix D where n is the number of vertices of 𝒢. For example, Foremost-path TGR is the following problem.

Foremost-path TGR:

Input: A number n and an n×n distance matrix D.

Question: Is there a temporal graph 𝒢 with n vertices such that Foremost⁡(𝒢)=D?

When considering an instance (n,I) of P TGR, we always let n denote the associated number. Note that, in the case of an M-path TGR instance, the input has size Θ⁢(n2). For brevity, given an input sequence I encoding a distance matrix D, a realization 𝒢 of I for M-path is simply called an M-realization of D. If the metric M is clear from the context, we simply say that 𝒢 is a realization of D or that 𝒢 realizes D.

We also combine M-path predicates with additional requirements. In particular, when the input I either encodes a (static) graph Gp with n nodes, or a period Δ, we define the following additional predicates, respectively:

  • ■

    Prescribed⁡(𝒢,Gp):= the underlying graph of 𝒢 is a subgraph of Gp,

  • ■

    Periodic⁡(𝒢,Δ):= 𝒢 is Δ-periodic.

Given two predicates P,Q, the problem “P Q TGR” asks whether there exists a temporal graph satisfying both P and Q for a given pair of inputs for P and Q. For example, Periodic Foremost-path TGR asks, given an n×n distance matrix D and a period Δ, whether there exists a Δ-periodic temporal graph that is a Foremost-realization of D. Similarly, Prescribed Foremost-path TGR supposes that, in addition to D, the input includes a static graph Gp called the prescribed graph, and asks whether there exists a Foremost-realization of D whose underlying graph is a subgraph of Gp. We also sometimes refer to “P Q TGR” as “Q TGR where P is required”, especially if P is specified in plain text without defining a formal name for it.

3 Foremost paths

We first consider the Foremost-path TGR problem. Recall that, given an n×n distance matrix D, it consists of checking whether there exists a temporal graph 𝒢 whose foremost matrix is D, i.e. Foremost⁡(𝒢)=D. We also consider its non-strict variant (NS−Foremost-path TGR), and combining both with Prescribed and Periodic additional requirements. Similar results can be obtained for latest departure using a time-reversal argument. We often implicitly assume that we are given an n×n distance matrix D.

We first show that these main variants of the problem can be solved in polynomial time.

3.1 Polynomial time algorithms

Strict Foremost paths

In the strict setting, we can indeed state the following.

Theorem 3.1.

Foremost-path TGR can be solved in 𝒪⁢(n3⁢log⁡n) time and 𝒪⁢(n2) space. Furthermore, if dealing with a realizable instance, a realization with at most n2 time labels can be computed with the same complexity.

The proof mainly comes from an algorithm given hereafter. First note that the above complexity can be expressed as 𝒪~⁢(N3/2) where N=Θ⁢(n2) is the size of the input. We also state that the above result is asymptotically tight in terms of the number of time labels as follows.

Proposition 3.2.

There exists a family (Dn)n∈ℕ>0 of n×n distance matrices that are Foremost-realizable where each realization requires Ω⁢(n2) time labels.

Proof.

Consider the temporal graph 𝒢n with n vertices, whose underlying graph is a star rooted at 1, and where, for all v>1, edge {1,v} appears at times n⁢v,n⁢(v+1)+v,n⁢(v+2)+v,…,n2+v. Its foremost matrix Dn=Foremost⁡(𝒢n) then satisfies Du⁢vn=n⁢u+v for u>v>1, Du⁢vn=n⁢v for 1<u<v, and D1⁢vn=Dv⁢1n=n⁢v for 1<v. These temporal graphs thus define a family (Dn)n∈ℕ>0 of distance matrices that are foremost realizable and that have Ω⁢(n2) pairwise distinct entries. This implies that any foremost realization of such a matrix Dn must have Ω⁢(n2) time labels. The reason is that any foremost realization 𝒢′ of an n×n distance matrix D containing p pairwise distinct entries must have at least p time labels. Indeed, any entry Du⁢v must correspond to some foremost temporal u⁢v-path in 𝒢′ whose last edge appears at time Du⁢v. ◀

▶ Remark.

The above lower bound also applies to non-strict foremost realizations (using a similar proof with the same families of matrices and temporal graphs). It also holds if we restrict the problem to sparse prescribed graphs with O⁢(n) edges, or even trees, as long as the star is a possible prescribed graph.

We now present a simple algorithm for computing a Foremost-realization that leads to 𝒪⁢(n4) time complexity; this bound will be improved subsequently. It is based on the observation that any realization 𝒢 of a distance matrix D for Foremost-path must satisfy the following compatibility property.

Definition 3.3 (Edge compatibility).

Given an n×n distance matrix D, a time-edge ({v,w},τ) is said to be Foremost-edge-compatible with D if it satisfies: E⁢d⁢g⁢e⁢C⁢o⁢m⁢p⁢a⁢t⁢(D,{v,w},τ):=∀x∈[n],Dx⁢v<τ⟹Dx⁢w≤τ⁢ and ⁢Dx⁢w<τ⟹Dx⁢v≤τ.

The intuition behind is the following. If an edge {v,w} appears at time τ in a temporal graph 𝒢, then any foremost temporal x⁢v-path with arrival time less than τ can be extended by the time-edge ({v,w},τ), implying that the foremost arrival time at w is at most τ. Moreover, if 𝒢 is a realization of D, i.e. D=Foremost⁡(𝒢), and Dx⁢v<τ, then we must have Dx⁢w≤τ. By symmetry of edges, we must also have Dx⁢w<τ⟹Dx⁢v≤τ. Note that, given an n×n distance matrix D and a time-edge ({v,w},τ), the property E⁢d⁢g⁢e⁢C⁢o⁢m⁢p⁢a⁢t⁢(D,{v,w},τ) can easily be tested in 𝒪⁢(n) time.

The algorithm behind Theorem 3.1 now consists of checking that for each entry τ=Du⁢w of D, there exists a vertex v such that Du⁢v<τ and the time-edge ({v,w},τ) is Foremost-edge-compatible with D. If this is the case, such a time-edge ({v,w},τ) is added to the temporal graph we are constructing (see Algorithm 1). This condition is indeed necessary as a foremost temporal u⁢w-path in a realization of D must end with such an edge. We will show that this condition is also sufficient, and leads to a construction of a realization with at most n2 time labels.

Algorithm 1 Foremost-path TGR.

The correctness of the algorithm comes with defining how a temporal graph can partially realize a matrix as follows.

Definition 3.4.

A temporal graph 𝒢 is said to be Foremost-compatible with D if D≤Foremost⁡(𝒢), i.e. Du⁢v≤Foremost(𝒢)u⁢v for all u,v∈[n], and all time-edges of 𝒢 are Foremost-edge-compatible with D.

First note that any Foremost-realization of D must be Foremost-compatible with D.

Lemma 3.5.

If 𝒢 is a Foremost-realization of D, then 𝒢 is Foremost-compatible with D.

Proof.

First, we clearly have D≤Foremost⁡(𝒢) since 𝒢 is a Foremost-realization of D. Second, suppose for the sake of contradiction that some time-edge ({v,w},τ) is not Foremost-edge-compatible with D. That is, without loss of generality, there exists a vertex x such that Dx⁢v<τ and Dx⁢w>τ. Any foremost temporal x⁢v-path in 𝒢 must arrive in v at time Dx⁢v. However, this temporal path can be extended with ({v,w},τ), yielding a temporal x⁢w-walk arriving at time τ<Dx⁢w, contradicting the fact that 𝒢 is a Foremost-realization of D. ◀

Note also that an n-vertex empty temporal graph, i.e. without any time labels, is always Foremost-compatible with D as it does not contain any time-edges. Moreover, Foremost-compatibility is preserved by addition of a Foremost-edge-compatible time-edge as stated below.

Lemma 3.6.

If a temporal graph 𝒢=(G,λ) is Foremost-compatible with D and a time-edge ({v,w},τ) is Foremost-edge-compatible with D, then the temporal graph 𝒢′ obtained from 𝒢 by adding label τ to edge {v,w} is also Foremost-compatible with D.

Proof.

We just need to prove D≤Foremost⁡(𝒢′). Suppose for the sake of contradiction that there exists x≠y such that Dx⁢y>Foremost(𝒢′)x⁢y, i.e., Dx⁢y is greater than the arrival time of a foremost temporal x⁢y-path P in 𝒢′. Consider the first time-edge ({z,z′},σ′) of P such that P arrives in z at time σ≥Dx⁢z but arrives in z′ before Dx⁢z′, i.e. σ′<Dx⁢z′. Such an edge must exist since P arrives in y before Dx⁢y and Dx⁢x=0. The (strict) temporal path definition implies σ<σ′ which thus yields Dx⁢z<σ′. As Dx⁢z′>σ′, ({z,z′},σ′) cannot be Foremost-edge-compatible with D. This contradicts either the Foremost-edge-compatibility of ({v,w},τ) if ({z,z′},σ′)=({v,w},τ), or the Foremost-compatibility of 𝒢 otherwise. ◀

Lemma 3.7.

If 𝒢 is a Foremost-realization of D, then for any entry τ=Du⁢w with u≠w, there exists a vertex v such that Du⁢v<τ and ({v,w},τ) is Foremost-edge-compatible with D.

Proof.

It suffices to consider the last time-edge ({v,w},τ) of a foremost temporal u⁢w-path in a Foremost-realization 𝒢 of D. It must satisfy τ=Du⁢w since 𝒢 is a realization of D. Since it is a strict temporal path, it arrives in v before τ, implying Du⁢v<τ. Moreover, ({v,w},τ) is Foremost-edge-compatible with D by Lemma 3.5. ◀

Proof of Theorem 3.1.

If there exists a Foremost-realization of D, the algorithm must find a suitable time-edge ({v,w},Du⁢w) for each pair (u,w) by Lemma 3.7. It thus returns NO, only when no such realization exists. Let Kn denote the complete graph with vertex set [n]. Lemma 3.6 implies that Algorithm 1 preserves the invariant that (Kn,λ) is Foremost-compatible with D. If the algorithm returns YES, the constructed temporal graph 𝒢=(Kn,λ) is thus Foremost-compatible with D, implying D≤Foremost⁡(𝒢). We now prove that we indeed must have D=Foremost⁡(𝒢). Suppose for the sake of contradiction that there are pairs (u,w) satisfying Du⁢w<Foremost(𝒢)u⁢w. Consider such a pair (u,w) such that Du⁢w is minimum. When this pair was considered, the algorithm added to 𝒢 a time-edge ({v,w},Du⁢w) satisfying Du⁢v<Du⁢w. By the choice of (u,w), we have Du⁢v=Foremost(𝒢)u⁢v. Now, if we extend a foremost temporal u⁢v-path in 𝒢 with ({v,w},Du⁢w), we obtain a temporal u⁢w-walk arriving at time Du⁢w in contradiction with Du⁢w<Foremost(𝒢)u⁢w. This concludes the proof of correctness of Algorithm 1.

Its time complexity is clearly 𝒪⁢(n4) as for each of the n2 pairs (u,w), we consider at most n vertices v and the test for the Foremost-edge-compatibility of ({v,w},Du⁢w) takes 𝒪⁢(n) time. To obtain 𝒪⁢(n3⁢log⁡n), we use an interval tree data-structure (see, e.g., [5]). It can store n intervals and querying whether a value τ is in one of these intervals can be answered in O⁢(log⁡n) time. It uses O⁢(n) space and can be constructed in O⁢(n⁢log⁡n) time. To benefit from such a data-structure, we consider all pairs (u,w) with fixed w consecutively. Before processing them, we compute for each vertex v two interval trees Tv and Tv′ where Tv (respectively Tv′) contains the n intervals [Dx⁢v+1,Dx⁢w−1] (respectively [Dx⁢w+1,Dx⁢v−1]) for x∈[n], ignoring empty intervals. The Foremost-edge-compatibility of a time-edge ({v,w},τ) can then be tested in O⁢(log⁡n) time by checking that neither Tv nor Tv′ has an interval containing τ. The reason is that any vertex x violating Dx⁢v<τ⟹Dx⁢w≤τ satisfies Dx⁢v<τ<Dx⁢w in which case τ belongs to the interval of Tv associated to x. Analogously, any vertex x violating Dx⁢w<τ⟹Dx⁢v≤τ is associated to an interval of Tv′ that contains τ. Constructing the interval trees takes O⁢(n2⁢log⁡n) time while processing each (u,w) pair now takes O⁢(n⁢log⁡n) time as it mainly consists of n Foremost-edge-compatibility tests. The overall complexity is thus O⁢(n3⁢log⁡n) time using O⁢(n2) space.

Note that the algorithm adds a time label to an edge {v,w} at most once for each vertex u, when considering either (u,w) or (u,v), depending on whether Du⁢v<Du⁢w or Du⁢w<Du⁢v. The Foremost-realization computed by Algorithm 1 thus has at most n time labels per edge, and at most n2 time labels in total. ◀

Non-strict foremost paths

We have a similar result for the non-strict case.

Theorem 3.8 (⋆).

NS-Foremost-path TGR can be solved in 𝒪⁢(n3⁢log⁡n) time and 𝒪⁢(n2) space. Furthermore, if dealing with a realizable instance, a realization with at most n2 time labels can be computed with the same complexity.

A slight modification of Algorithm 1 suffices, replacing E⁢d⁢g⁢e⁢C⁢o⁢m⁢p⁢a⁢t⁢(D,{v,w},τ) with:

NSEdgeCompat(D,{v,w},τ):=∀x∈[n],Dx⁢v≤τ⟺Dx⁢w≤τ.

The change of < for ≤ accounts for considering non-strict temporal paths rather than strict ones. This modification requires a different version of Lemma 3.7 with a significantly different proof where a non-strict temporal v⁢w-path whose edges are traversed at same time τ in a realization is replaced by a single time-edge ({v,w},τ) (see Lemma 3.12 in the full version).

Periodic temporal graph and prescribed graph

It is straightforward to generalize Theorem 3.1 to Periodic Foremost-path TGR and Prescribed Foremost-path TGR with appropriate definitions of edge compatibility (see Therems 3.13 and 3.14 in the full version).

Non-strict foremost paths with a prescribed graph

In this setting, a prescribed graph Gp=([n],Ep) is additionally given as input, and the realization is required to have a subgraph of Gp as underlying graph. We let Np⁢(v)={w:∃{v,w}∈Ep} denote the set of neighbors of any vertex v∈[n] in Gp.

The main idea is again to add time-edges ({v,w},τ) that satisfy N⁢S⁢E⁢d⁢g⁢e⁢C⁢o⁢m⁢p⁢a⁢t⁢(D,{v,w},τ) and such that {v,w} is present in the prescribed graph. But conversely to the non-strict setting considered in Theorem 3.8, it is not possible to replace an instantaneous temporal v⁢w-path (whose edges are traversed at the same time) in a realization by a single appearance of {v,w} as this edge might not be in the prescribed graph.

Indeed, the condition Du⁢v<Du⁢w at Line 6 of Algorithm 1 now becomes problematic as the prescribed graph may impose the addition of a time-edge ({v,w},Du⁢w) such that Du⁢v=Du⁢w to fulfill an entry Du⁢w. Moreover, the order in which we can fulfill entries Du⁢w1=⋯=Du⁢wp in this manner may depend on the prescribed graph. A naive solution would be to let each edge {v,w}∈Ep appear at all times τ∉{0,∞} appearing in D that satisfy N⁢S⁢E⁢d⁢g⁢e⁢C⁢o⁢m⁢p⁢a⁢t⁢(D,{v,w},τ). It would then suffice to check if the resulting temporal graph is an NS−Foremost-realization of D. However, this would result in a poor complexity and possibly Θ⁢(n4) time labels overall. We can still solve the problem with a better complexity and a tight number of time labels as stated below.

Theorem 3.9 (⋆).

Prescribed NS-Foremost-path TGR can be solved in 𝒪⁢(n2⁢m) time and 𝒪⁢(n2) space, where m is the number of edges of the prescribed graph. Furthermore, if dealing with a realizable instance, a realization with at most n2 time labels can be computed with the same complexity.

The result is a consequence of an algorithm that works as follows: It scans the set {d1,…,dp} of entries of D excluding 0 and ∞ (in any order). For each di, it checks the set Ci of all pairs (u,w) such that Du⁢w=di. If there exists a vertex v∈Np⁢(w) such that Du⁢v<Du⁢w and N⁢S⁢E⁢d⁢g⁢e⁢C⁢o⁢m⁢p⁢a⁢t⁢(D,{v,w},di) is satisfied, it adds label Du⁢w to {v,w}, similarly to Algorithm 1. In addition, it starts a BFS like procedure to find other pairs (u,w′)∈Ci that can be reached at time di through w. See Algorithm 2 in the full version for more details.

3.2 Limits of polynomial-time algorithms for Foremost-path TGR

In this section, we show several additional requirements on instances of Foremost-path TGR for which the problem becomes NP-hard.

Theorem 3.10 (⋆).

Foremost-path TGR is NP-hard when allowing at most one label per edge.

Foremost paths in ranges

Given a temporal path metric M, we define the following variant of M-path TGR where the input sequence encodes a matrix D of ranges. More precisely, each entry is supposed to represent a range [ℓ,r]={ℓ,…,r} of positive integers. The Ranged-M-path predicate is then defined as P⁢(𝒢,D):=M⁢(𝒢)u⁢v∈Du⁢v for all u,v∈[n]. For example, this leads to the following problem for M=Foremost.

Ranged-Foremost-path TGR:

Input: A number n and an n×n matrix D of ranges.

Question: Is there a temporal graph 𝒢 such that Foremost(𝒢)u⁢v∈Du⁢v for all u,v∈[n]?

An entry (u,v) is said to be undetermined if Du⁢v=[ℓ,r] with ℓ≠r. Note that when the number k of undetermined entries is zero, this problem is equivalent to Foremost-path TGR, for which we presented a polynomial-time algorithm. We now analyze the complexity of Ranged-Foremost-path TGR and its non-strict variant Ranged-NS-Foremost-path TGR with a focus on the parameter k.

Theorem 3.11 (⋆).

Ranged-Foremost-path TGR and Ranged-NS-Foremost-path TGR are both NP-hard. Moreover, believing the ETH, neither Ranged-Foremost-path TGR nor Ranged-NS-Foremost-path TGR can be solved in 2o⁢(k)⋅n𝒪⁢(1) time, where k is the number of undetermined entries of D.

For the strict setting, we obtain hardness even when each range has size at most 2.

Theorem 3.12 (⋆).

Ranged-Foremost-path TGR is NP-hard even when each range has length at most two and the largest value of the matrix is 5.

FPT algorithm for Ranged-Foremost-path TGR

We now propose a dynamic programming algorithm solving Ranged-Foremost-path TGR which has running time 2𝒪⁢(k)⋅n𝒪⁢(1). Note that this is tight in the sense that a significantly faster algorithm would contradict ETH by Theorem 3.11.

Theorem 3.13 (⋆).

Ranged-Foremost-path TGR can be solved in 𝒪⁢(k2⁢3k⁢n4) time and 𝒪⁢(2k+n2) space, where k is the number of undetermined entries of D.

In the following, we let ℓu⁢w (respectively ru⁢w) denote the lower bound (respectively upper bound) of entry (u,w), i.e., Du⁢w=[ℓu⁢w,ru⁢w]. Recall that an entry (u,w) is undetermined if ℓu⁢w≠ru⁢w. The set of such undetermined entries is denoted by U⁢n⁢d⁢e⁢t and its size is denoted by k.

This result relies on the fact that a realizable instance can always be realized by a temporal graph using time labels in the restricted set 𝒯={ℓu⁢w+j∣u≠w⁢ and ⁢0≤j≤k} (as proven in the full version). We then propose an algorithm that processes all times in 𝒯 in increasing order and guesses which undetermined entries can be realized at the current time. More precisely, letting 0<τ1<⋯<τm denote the times in 𝒯, we maintain, for each i∈[m], a table R⁢[⋅,i] such that R⁢[S,i] for S⊆U⁢n⁢d⁢e⁢t is equal to True if and only if there exists a temporal graph 𝒢 with time labels in {τ1,…,τi} such that:

  • ■

    for each (u,w)∈S, the earliest arrival time of any foremost temporal u⁢w-path in 𝒢 is in Du⁢w and is at most τi,

  • ■

    for each (u,w) with ℓu⁢w=ru⁢w=τ≤τi, the earliest arrival time of any foremost temporal u⁢w-path in 𝒢 is τ,

  • ■

    for all other entries (u,w), there is no temporal u⁢w-path in 𝒢.

We have that R⁢[U⁢n⁢d⁢e⁢t,m]=T⁢r⁢u⁢e if and only if there exists a temporal graph that realizes D for Ranged-Foremost-path.

When processing time τi, we consider tri-partitions S,T,U of the set U⁢n⁢d⁢e⁢t where S represents the set of undetermined entries that must be realized before time τi, T represents the set of undetermined entries that must be realized at time τi and U the set of undetermined entries that must be realized after time τi. Similarly to Algorithm 1, an appropriate definition of edge compatibility (with respect to D, S and T) allows to test if a temporal graph realizing R⁢[S,i−1]=T⁢r⁢u⁢e can be completed in order to set R⁢[S∪T,i]. Importantly, we do not need explicit access to such a temporal graph as we probe it through D,S,T.

▶ Remark.

The algorithm proposed here can easily be generalized to a more general setting where a collection of ranges is given for each entry of D with time complexity 𝒪⁢(k2⁢3k⁢n2⁢N) where N≥n2 denotes the total number of ranges in D. In particular, this provides an FPT algorithm for Ranged-Foremost-path TGR when each entry of D encodes a set of integers and at most k of them are non-singletons. Note that the hardness result of Theorem 3.12 holds in that setting, even if each set has size at most 2.

4 Fastest paths

In this section we consider temporal graph realization for fastest paths analyzed by Klobas et al. [16] and Erlebach et al. [11]. We answer an open question by both papers about the parameterized complexity with respect to the vertex cover number.

So far, Fastest-path TGR has only been considered for strict temporal paths, and if we consider a periodic temporal graph or if we consider the non-periodic version with a limited number of labels per edge [16, 11]. Our parameterized hardness result holds even for non-periodic temporal graph with arbitrary many labels per edge and without limiting the lifetime of the sought temporal graph. We then show that this hardness is preserved in the periodic case with one label per edge per period to answer the open questions.

Theorem 4.1 (⋆).

Fastest-path TGR is NP-hard and W[1]-hard when parameterized by the vertex cover number of the underlying graph plus the largest entry of D. This holds even on a family of instances for which all yes-instances are realizable with only one label per edge.

Proof (sketch)..

We reduce from Multicolored Clique [6].

Multicolored Clique:

Input: An undirected graph G=(V,E), an integer k, and a k-partition (V1∪⋯∪Vk) of V, such that Vi is an independent set in G for each i∈[1,k].

Question: Is there a clique of size k in G?

Let I:=(G=(V1∪⋯∪Vk,E),k) be an instance of Multicolored Clique where for each 1≤a<b≤k, G⁢[Va∪Vb] is a disjoint union of bicliques. For each a∈[1,k], we call Va a color class. Even under these restrictions, Multicolored Clique is NP-hard and W[1]-hard when parameterized by k [22]. Let V:=V1∪⋯∪Vk.

To obtain an instance D of Fastest-path TGR as follows, we first describe the underlying graph, that is, the graph G′ that contains an edge {u,v} if and only if Du,v=1. The graph G′ is defined over the vertex set V′:=V∪{s,s′,s′′,t,t′,t′′}∪X∪L, where L is a vertex set of size 2⁢k+2 and X:={xi∣1≤i≤k+1} (see Figure 1). We add edges between these vertices, such that V′∖V is a vertex cover of G′. That is, there are no edges between the vertices of V in G′. We make L into a clique and adjacent to all vertices of V′ besides s and t. Similarly, we make the vertices s′ and s′′ adjacent to all vertices of V′ besides t and make the vertices t′ and t′′ adjacent to all vertices of V′ besides s. Additionally, we make x1 adjacent to the vertices of V1, xk+1 adjacent to the vertices of Vk, and for each i∈[2,k], we make xi adjacent to the vertices of Vi−1∪Vi. There are no edges between the vertices of X. Finally, we make s adjacent to s′,s′′, and x1, and we make t adjacent to t′,t′′, and xk+1.

This completes the underlying graph G′ and thus all entries of the matrix D of value 1. Let E′ denote the edges of G′. Next, we define the remaining entries. Note that each vertex of {s′,s′′,t′,t′′}∪L is adjacent to each other vertex of V′∖{s,t}. Hence, for these vertices it remains to define the entries of the table from and to the vertices s and t. We set Ds,q:=Dq,s:=2⁢k+3 for each vertex q∈{t′,t′′}∪L. Similarly, we set Dt,p:=Dp,t:=2⁢k+3 for each vertex p∈{s′,s′′}∪L. For each non-edge {u,v} of G, we set Du,v:=Dv,u:=2⁢k+3. Finally, we set Ds,t:=2⁢k+2 and Dt,s:=4⁢k+5. All other undefined entries are set to 2. This completes the construction. Note that X∪L∪{s′,s′′,t′,t′′} is a vertex cover of size 3⁢k+7 and that the largest entry in D is 4⁢k+5.

Figure 1: An illustration of the underlying graph from the reduction behind Theorem 4.1. The edges of the biclique (L∪{s′,s′′,t′,t′′},V∪X) are not depicted. Note that L is a clique of size 2⁢k+2.
Intuition.

The idea behind the reduction is that realizing all entries besides Ds,t is possible, regardless of whether G contains a (multicolored) clique of size k. We will show that this is ensured by the fact that G⁢[Vi∪Vj] with 1≤i<j≤k is a disjoint union of bicliques. The difficulty to decide whether the matrix is realizable thus comes from the difficulty of deciding whether the entry Ds,t can additionally be realized, which can only be done by using vertices of X∪V as intermediate vertices of the path. Let S denote the vertices of V on any path P realizing the entry Ds,t=2⁢k+2. Based on the structure of the underlying graph (see Figure 1), S contains for each i∈[1,k] at least one vertex of Vi. By definition of the entries between vertices of V, these vertices need to form a clique in the original graph, as only adjacent vertices u and v in G fulfill Du,v≤2⁢k+2, which is the duration of P.

Correctness.

We now show that D is realizable if and only if G admits a clique of size k. More precisely, we show that if G admits a clique of size k, then there is a realization for D with exactly one label per edge.

(⇒)

Let λ:E′→2ℕ be an edge labeling, such that 𝒢:=(G′,λ) realizes D. We show that G has a clique of size k. Consider the entry Ds,t=2⁢k+2. Since 𝒢 is a realization of D, this implies that the fastest temporal path from s to t has duration exactly 2⁢k+2. Let P be an arbitrary fastest temporal path from s to t in 𝒢. Since the duration of P is 2⁢k+2, the duration of each (not necessarily proper) subpath of P is at most 2⁢k+2. Hence, for any two distinct vertices a,b of P, where a precedes b in P, the entry Da,b is at most 2⁢k+2, as D is realized by 𝒢. This immediately implies that P does not visit any vertex of {s′,s′′,t′,t′′}∪L, since Ds,t′=Ds,t′′=Ds′,t=Ds′′,t=2⁢k+3 and Ds,ℓ=Dℓ,t=2⁢k+3 for each vertex ℓ∈L. That is, P only uses vertices of V∪{s,t}∪X. By definition, each path from s to t in G′⁢[V∪{s,t}∪X] traverses all vertices of X and one vertex of each of the color classes of V, that is, for each i∈[1,k], the path contains one vertex of Vi. This in particular holds for P. Let S be the vertices of V that are visited by P. By the above, S has size at least k. Moreover, for each two distinct vertices a and b of S, Da,b=Db,a≤2⁢k+2, since the subpath between a and b of P has duration at most 2⁢k+2 and 𝒢 realizes D. This implies that {a,b} is an edge of G, as otherwise, Da,b=Db,a is defined as 2⁢k+3. Consequently, S is a clique of size k in G.

(⇐)

Let S be a clique of size k in G and for each i∈[1,k], let vi denote the unique vertex of S∩Vi. We define a labeling λ:E′→ℕ, such that 𝒢:=(G′,λ) realizes D. To this end, we describe several time blocks, that is, intervals [α,β] with β≥α+4⁢k+6, such that only the described edges receive a label from this interval, and all other edges receive no label from [α−(4⁢k+6),β+(4⁢k+6)]. The reason behind this is that labeling edges in different time blocks do not create paths of duration less than 4⁢k+6, which is larger than the largest entry of D. Hence, we can show that our labeling realizes D by showing that for each two vertices a and b of G′ (i) there is a time block in which there is a temporal path from a to b of duration exactly Da,b and (ii) for each time block, there is no temporal path from a to b of duration less than Da,b. Note that the order of time blocks does not matter. Hence, when describing the labeling, we simply describe a collection of time blocks which in total fulfill the above properties, while not explicitly defining the concrete start and end time of the time blocks. In the following, we mainly focus on realizing all entries of value at least 2 in D. Afterwards, we describe how to realize the entries of value 1.

  • ■

    Realizing all entries involving vertices of V′∖(V∪X) besides Ds,t.

    We show that we can realize all these entries by only labeling edges that have at least one endpoint in {s′,s′′,t′,t′′}. This proof is deferred to the full version.

  • ■

    Realizing Ds,t. Next, we define a time block [α,β] that realizes the entry Ds,t. Recall that S is a clique in G and that for each i∈[1,k], vi denotes the vertex of S∩Vi. Consider the path P:=(s,x1,v1,…,xk,vk,xk+1,t) and label the edges of this path with consecutive time labels starting with α. Hence, this path has duration equal to its length, namely Ds,t=2⁢k+2.

    The argument that this creates no paths that are too fast is deferred to the full version. It mainly comes from the fact that for any two vertices a and b of P that are both from V, {a,b}∈E since S is a clique, and we have Da,b=2.

So far, we have realized all entries of D of value at least 2 that involve at least one vertex of {s,s′,s′′,t,t′,t′′}∪L. In the following, we describe further time blocks to realize the entries of D of value at least 2 involving only vertices of V∪X. To this end, we will only use edges between X∪V and L. Note that none of these edges has received a label in the previous time blocks, that is, the only edges incident with vertices of L that received labels so far were the edges between L and {s′,s′′,t′,t′′}. Let the vertices of L be called {ℓ∗,ℓ∗∗}∪{ℓi,ℓi′∣1≤i≤k}.

  • ■

    Realizing entries between vertices of V of value 𝟐⁢k+𝟑 and entries between vertices of V and X. We define a time block [α,β] as follows: For each vertex v∈V, we set λ⁢({v,ℓ∗}):=α+1 and λ⁢({v,ℓ∗∗}):=α+2⁢k+3. For each vertex x∈X, we set λ⁢({x,ℓ∗}):=α and λ⁢({x,ℓ∗∗}):=α+2⁢k+4. Finally, we set λ⁢({ℓ∗,ℓ∗∗})=α+2. Note that each vertex of V has only two incident labels in this time block, namely, α+1 and α+2⁢k+3. Hence, no temporal path in this time block between vertices of V has duration less than 2⁢k+3. Moreover, since entries involving a vertex from V and a vertex from X are of value at most 2, we guarantee that we do not create paths that are too fast in this time block. We now show that this time block realizes (i) all entries of value at least 2 between vertices of V and X and (ii) all entries between vertices of V of value 2⁢k+3. For the first type, let v∈V and x∈X with {v,x}∉E′. That is, Dx,v=2. Then, there is a temporal path (x,ℓ∗,v) in this time block of duration 2. Similarly, the temporal path (v,ℓ∗∗,x) also has duration 2. Now consider the second type. For each two distinct vertices u and v of V with Du,v≠2, there is the temporal path (u,ℓ∗,ℓ∗∗,v) with labels (α+1,α+2,α+2⁢k+3). This path has duration 2⁢k+3=Du,v. This time block realizes the stated entries of D.

  • ■

    Realizing entries between vertices of X. For each i∈[1,k], we define a time block [αi,βi] in which we set λ⁢({xi,ℓi}):=αi and λ⁢({ℓi,x}):=αi+1 for each x∈X∖{xi}. For each i∈[1,k], this realizes the entries Dxi,x with x∈X∖{xi}. Similarly, we add a time block [αk+1,βk+1] in which we set λ⁢({xk+1,ℓ1′}):=αk+1 and λ⁢({ℓ1′,x}):=αk+1+1 for each x∈X∖{xk+1}. These time blocks realize all entries of D between vertices of X.

  • ■

    Realizing entries between vertices of V of value 𝟐. Recall that we have to ensure that there is a path of duration 2 between the endpoints of each edge e∈E in our temporal graph. To define the necessary time blocks, we will highly rely on the fact that for each 1≤a<b≤k, G⁢[Va∪Vb] is a vertex disjoint union of bicliques. This property will allow us to realize all edges between Va and Vb via just two vertices of L. We can do this for several combinations of color classes via the same two vertices of L, as long as no color class occurs in more than one pair. We formalize this as follows. Let M1,…,Mk be a partition of {(a,b)∣1≤a<b≤k}, such that for each i∈[1,k] and each a∈[1,k], there is at most one ordered pair in Mi that contains a. That is, Mi is a matching in the directed graph with vertex set [1,k] and edge set {(a,b)∣1≤a<b≤k}. Note that such a partition exists due to the fact that a clique on k vertices has a proper edge coloring with k colors. Let i∈[1,k]. We let EMi denote all edges of G between each pair of color classes in Mi, that is, EMi:=⋃(a,b)∈MiE⁢(Va,Vb). Since Mi is a matching and G⁢[Va∪Vb] is a disjoint union of bicliques for each 1≤a<b≤k, Gi:=(V,EMi) is also a disjoint union of bicliques. That is, each connected component in Gi is a biclique. We use the vertices ℓi and ℓi′ of L to realize the entries of D corresponding to the edges of EMi. For each connected component of Gi with bipartition (A,B), we add a new time block [α,β] and set λ⁢({va,ℓi}):=α for each va∈A and λ⁢({vb,ℓi}):=α+1 for each vb∈B. This realizes paths of duration 2 from each vertex of A to each vertex of B and no other temporal paths of length more than 1. Since (A,B) is a biclique, for all these vertex pairs, the entry in the matrix is also 2. In the same way, we also add a new time block [α′,β′] and set λ⁢({vb,ℓi′}):=α for each vb∈B and λ⁢({va,ℓi′}):=α+1 for each va∈A. This thus realizes also the entries of duration 2 from each vertex of B to each vertex of A. Since E=⋃i∈[1,k]EMi, this implies that we realized the entries Du,v and Dv,u of value 2 by the above time blocks for each edge {u,v}∈E.

Hence, all entries of value at least 2 in D are realized by λ. Let E′′ denote the edges of E′ that have not received a label yet. We add one final time block from which all edges of E′′ receive the same label. This surely does not create new temporal paths of length more than 1 for which the duration is at most 4⁢k+5. This completes the definition of λ. Thus, also all entries of value 1 are realized. By definition of the time blocks, we showed that (G′,λ) realizes the input matrix D even with just a single label per edge. ◀

Based on this reduction, we can now directly transfer the hardness result to Periodic Fastest-path TGR even when allowing at most one label per edge.

That is, we simply define the period Δ to be an integer much larger than n2⋅max⁡D, which ensures that all fastest paths start and end within a window of Δ consecutive time steps (see [11]).

Theorem 4.2.

Even when only allowed to put one label per edge and per period, Periodic Fastest-path TGR is W[1]-hard when parameterized by the vertex cover number of the underlying graph plus the largest entry of D.

This answers an open question by Klobas et al. [16] and Erlebach et al. [11] about the parameterized complexity of the problem with respect to the vertex cover number. Furthermore, this reduction improves significantly over the known hardness result for parameter feedback vertex set number. It also shows that Periodic Fastest-path TGR can presumably not be solved in FPT time for the combined parameter of the vertex cover number plus ℓ (the number of allowed labels per edge and per period) plus the largest entry in D. Thus, in the FPT algorithm by Erlebach et al. [11] for the vertex cover number plus the period Δ (or lifetime), one cannot replace Δ by ℓ plus the largest entry of D.

A similar reduction also shows similar intractability results for Fastest-path TGR with non-strict paths. The following reduction however requires more than one label per edge.

Theorem 4.3 (⋆).

NS-Fastest-path TGR is NP-hard and W[1]-hard when parameterized by the vertex cover number of the underlying graph plus the largest entry of D.

5 Shortest paths

In this section, we consider the question for shortest temporal paths.

Shortest-path TGR:

Input: A distance matrix D of size n×n.

Question: Is there a temporal graph 𝒢 such that Shortest⁡(𝒢)=D?

Note that a realization of D can only assign labels to edges {u,v} where Du,v=Dv,u=1. Hence, G=([n],E) with E:={{u,v}∣Du,v=1∧Dv,u=1} is the underlying graph of every realization of D. We show the NP-hardness of both the strict and the non-strict variants.

Theorem 5.1 (⋆).

Shortest-path TGR and NS-Shortest-path TGR are NP-hard.

Proof (sketch)..

We reduce from SAT.

Let F be an instance of SAT where each variable occurs at least once positively and at least once negatively, and where no clause contains the same variable both positively and negatively.

Construction.

Let X be the variable set of F and let C denote the clauses of F. To obtain an instance D of Shortest-path TGR or NS-Shortest-path TGR, we first define the underlying graph G=(V,E) that contains an edge {u,v} if and only if Du,v=Dv,u=1 (see Figure 2). The graph G contains for each variable x∈X the vertices x and x¯ which are joined by an edge. For each clause c∈C, we also add a vertex c, which we make adjacent to all vertices corresponding to literals that are contained in c. Additionally, we add three more vertices to G: a vertex v∗ which is adjacent to all vertices of C, and two vertices ⊤ and ⊥ that are adjacent to all vertices representing literals, that is, to the vertices of {x,x¯∣x∈X}.

Next, we describe the remaining entries of D. Let c be a clause of C. We set Dc,⊤:=3 and D⊤,c:=Dc,⊥:=D⊥,c:=2. For each other clause c′ of C, we set Dc,c′:=Dc′,c:=2. For each positive literal x that occurs in c, we set Dc,x¯:=Dx¯,c:=2. Similarly, for each negative literal x¯ that occurs in c, we set Dc,x:=Dx,c:=2. For each variable x for which neither x nor x¯ occurs in c, we set Dc,x¯:=Dx¯,c:=Dc,x:=Dx,c:=3. This defines all entries regarding vertices of C.

Let ℓ1 and ℓ2 be distinct literals, such that they are not the negation of each other. We set Dℓ1,ℓ2:=Dℓ2,ℓ1:=2. For each literal ℓ, we also set Dℓ,v∗:=Dv∗,ℓ:=2.

Finally, we set Dv∗,⊥:=D⊥,v∗:=3, D⊥,⊤:=D⊤,⊥:=2, Dv∗,⊤:=4, and D⊤,v∗:=3. This completes the definition of D.

Note that nearly all defined entries are the exact distances between the vertices in the underlying graph G. The only exceptions are the entry Dv∗,⊤ and the entry Dc,⊤ for each clause c∈C. Hence, only for the vertex pairs ({v∗}∪C)×{⊤}, one could possibly create a temporal path that has length less than the respective entry of D. Based on this property, we can prove that a labeling λ:E→2ℕ realizes D by showing the following two points:

  • ■

    For distinct vertices a and b of V, there is a temporal path of length Da,b from a to b.

  • ■

    For each a∈{v∗}∪C, there is no temporal path of length less than Da,⊤ from a to ⊤.

Figure 2: An example of the reduction behind Theorem 5.1 for the formula (x∨y∨z)∧(x¯∨y)∧(y¯∨z¯). A labeling that realizes the matrix D is depicted, where the dashed arcs receive the label set {1,2,7,8}. Moreover this labeling corresponds to a satisfying truth assignment (x = False, y = True, z = False).
Intuition.

We have clause vertices that aim to reach ⊤. For each such clause vertex ci, we want that the shortest temporal path to ⊤ has length exactly 3. By the structure of the implicit underlying graph, these paths must be of the form (ci,ℓ,ℓ¯,⊤) for some literal ℓ that occurs in clause ci. If two clauses try to use the same variable gadget from different sides to realize their entries, that is, if (ci,ℓ,ℓ¯,⊤) and (cj,ℓ¯,ℓ,⊤) are both temporal paths in our solution graph, then in fact at least one of (ci,ℓ,⊤) or (cj,ℓ¯,⊤) is also a temporal path, implying that for at least one of the clauses, the shortest temporal path has length 2, which is lower than the desired length of 3. Intuitively, this means that in each solution, each variable gadget can only be used in one direction for paths between clauses and ⊤, which then encodes a satisfying truth assignment.

The correctness is deferred to the full version. ◀

Note that a realization question for shortest temporal paths in periodic temporal graphs is polynomial time solvable. Due to the periodicity, a shortest path in the underlying static graph will always be a shortest temporal path in the periodic temporal graph where each edge receives at least one label. Since the latter is mandatory, the resulting problem is answered with yes if and only if the given matrix D is the distance matrix of the underlying graph.

6 Conclusion

Our work spawns several interesting future questions.

  • ■

    We showed that Foremost-path TGR is polynomial-time solvable if we are allowed to assign up to n labels per edge but becomes NP-hard when allowing only a single label per edge. What is the smallest number of labels per edge for which this problem is still polynomial-time solvable? For example, is there an efficient algorithm when we are allowed to assign only n2 labels per edge?

  • ■

    Our hardness results for Shortest-path TGR use multiple labels per edge. Does this problem become polynomial-time solvable, if we restrict the respective labeling? For example, what if we enforce that at most one label per edge is allowed or we require a proper labeling, that is, a labeling where no two adjacent edges share a label?

  • ■

    Are there structural parameters for which we can solve Shortest-path TGR in FPT-time. For example, can we solve the problem efficiently if the underlying graph has bounded treewidth?

  • ■

    One could consider approximation of the considered problems. For example under the measurement of fulfilling as many entries as possible, are there constant factor approximations for Shortest-path TGR or Fastest-path TGR?

References

  • [1] Eleni C. Akrida, Leszek Gąsieniec, George B. Mertzios, and Paul G. Spirakis. The complexity of optimal design of temporally connected graphs. Theory Comput. Syst., 61(3):907–944, 2017. doi:10.1007/S00224-017-9757-X.
  • [2] Amotz Bar-Noy, Keerti Choudhary, David Peleg, and Dror Rawitz. Efficiently realizing interval sequences. SIAM J. Discret. Math., 34(4):2318–2337, 2020. doi:10.1137/20M1326489.
  • [3] Arnaud Casteigts, Michelle Döring, and Nils Morawietz. Realization of Temporally Connected Graphs Based on Degree Sequences. In Proceedings of the 36th International Symposium on Algorithms and Computation (ISAAC), 2025. doi:10.48550/arXiv.2504.17743.
  • [4] Arnaud Casteigts, Paola Flocchini, Walter Quattrociocchi, and Nicola Santoro. Time-varying graphs and dynamic networks. Int. J. Parallel Emergent Distributed Syst., 27(5):387–408, 2012. doi:10.1080/17445760.2012.668546.
  • [5] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, 3rd Edition, chapter 14.3. MIT Press, 2009. URL: http://mitpress.mit.edu/books/introduction-algorithms.
  • [6] Marek Cygan, Fedor V. Fomin, Lukasz Kowalik, Daniel Lokshtanov, Dániel Marx, Marcin Pilipczuk, Michal Pilipczuk, and Saket Saurabh. Parameterized Algorithms. Springer, 2015. doi:10.1007/978-3-319-21275-3.
  • [7] Argyrios Deligkas and Igor Potapov. Optimizing reachability sets in temporal graphs by delaying. Inf. Comput., 285(Part):104890, 2022. doi:10.1016/J.IC.2022.104890.
  • [8] Jessica A. Enright, Kitty Meeks, George B. Mertzios, and Viktor Zamaraev. Deleting edges to restrict the size of an epidemic in temporal networks. J. Comput. Syst. Sci., 119:60–77, 2021. doi:10.1016/J.JCSS.2021.01.007.
  • [9] Paul Erdős and Tibor Gallai. Graphs with prescribed degrees of vertices. Mat. Lapok, 11:264–274, 1960.
  • [10] Thomas Erlebach, Othon Michail, and Nils Morawietz. Recognizing and Realizing Temporal Reachability Graphs. In Proceedings of the 33rd Annual European Symposium on Algorithms (ESA), 2025. doi:10.48550/arXiv.2503.15771.
  • [11] Thomas Erlebach, Nils Morawietz, and Petra Wolf. Parameterized algorithms for multi-label periodic temporal graph realization. Theoretical Computer Science, 1051:115412, 2025. doi:10.1016/j.tcs.2025.115412.
  • [12] F. Göbel, J. Orestes Cerdeira, and Henk Jan Veldman. Label-connected graphs and the gossip problem. Discret. Math., 87(1):29–40, 1991. doi:10.1016/0012-365X(91)90068-D.
  • [13] S. Louis Hakimi and S. S. Yau. Distance matrix of a graph and its realizability. Quarterly of Applied Mathematics, 22:305–317, 1965. URL: https://api.semanticscholar.org/CorpusID:118924338.
  • [14] David Kempe, Jon M. Kleinberg, and Amit Kumar. Connectivity and inference problems for temporal networks. In F. Frances Yao and Eugene M. Luks, editors, Proceedings of the Thirty-Second Annual ACM Symposium on Theory of Computing, May 21-23, 2000, Portland, OR, USA, pages 504–513. ACM, 2000. doi:10.1145/335305.335364.
  • [15] Nina Klobas, George B. Mertzios, Hendrik Molter, and Paul G. Spirakis. The complexity of computing optimum labelings for temporal connectivity. J. Comput. Syst. Sci., 146:103564, 2024. doi:10.1016/J.JCSS.2024.103564.
  • [16] Nina Klobas, George B. Mertzios, Hendrik Molter, and Paul G. Spirakis. Temporal graph realization from fastest paths. Theoretical Computer Science, 1056:115508, 2025. doi:10.1016/j.tcs.2025.115508.
  • [17] George B. Mertzios, Othon Michail, Ioannis Chatzigiannakis, and Paul G. Spirakis. Temporal network optimization subject to connectivity constraints. In Fedor V. Fomin, Rusins Freivalds, Marta Z. Kwiatkowska, and David Peleg, editors, Automata, Languages, and Programming - 40th International Colloquium, ICALP 2013, Riga, Latvia, July 8-12, 2013, Proceedings, Part II, volume 7966 of Lecture Notes in Computer Science, pages 657–668. Springer, 2013. doi:10.1007/978-3-642-39212-2_57.
  • [18] George B. Mertzios, Othon Michail, and Paul G. Spirakis. Temporal network optimization subject to connectivity constraints. Algorithmica, 81(4):1416–1449, 2019. doi:10.1007/S00453-018-0478-6.
  • [19] George B. Mertzios, Hendrik Molter, Nils Morawietz, and Paul G. Spirakis. Realizing temporal transportation trees. In Proceedings of the 51st Workshop on Graph-Theoretic Concepts in Computer Science (WG), 2025. URL: https://arxiv.org/abs/2403.18513.
  • [20] George B. Mertzios, Hendrik Molter, Nils Morawietz, and Paul G. Spirakis. Temporal Graph Realization With Bounded Stretch. In Proceedings of the 50th International Symposium on Mathematical Foundations of Computer Science (MFCS), 2025. doi:10.48550/arXiv.2504.14258.
  • [21] Julia Meusel, Matthias Müller-Hannemann, and Klaus Reinhardt. Directed temporal tree realization for periodic public transport: Easy and hard cases. In Proceedings of the 25th Symposium on Algorithmic Approaches for Transportation Modelling, Optimization, and Systems (ATMOS), 2025. doi:10.48550/arXiv.2504.07920.
  • [22] Nils Morawietz, Carolin Rehs, and Mathias Weller. A timecop’s work is harder than you think. In Javier Esparza and Daniel Král’, editors, 45th International Symposium on Mathematical Foundations of Computer Science, MFCS 2020, August 24-28, 2020, Prague, Czech Republic, volume 170 of LIPIcs, pages 71:1–71:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2020. doi:10.4230/LIPIcs.MFCS.2020.71.
  • [23] Philipp Zschoche, Till Fluschnik, Hendrik Molter, and Rolf Niedermeier. The complexity of finding small separators in temporal graphs. J. Comput. Syst. Sci., 107:72–92, 2020. doi:10.1016/J.JCSS.2019.07.006.