Safety in $s$-$t$ Paths, Trails and Walks

Given a directed graph $G$ and a pair of nodes $s$ and $t$, an \emph{$s$-$t$ bridge} of $G$ is an edge whose removal breaks all $s$-$t$ paths of $G$ (and thus appears in all $s$-$t$ paths). Computing all $s$-$t$ bridges of $G$ is a basic graph problem, solvable in linear time. In this paper, we consider a natural generalisation of this problem, with the notion of"safety"from bioinformatics. We say that a walk $W$ is \emph{safe} with respect to a set $\mathcal{W}$ of $s$-$t$ walks, if $W$ is a subwalk of all walks in $\mathcal{W}$. We start by considering the maximal safe walks when $\mathcal{W}$ consists of: all $s$-$t$ paths, all $s$-$t$ trails, or all $s$-$t$ walks of $G$. We show that the first two problems are immediate linear-time generalisations of finding all $s$-$t$ bridges, while the third problem is more involved. In particular, we show that there exists a compact representation computable in linear time, that allows outputting all maximal safe walks in time linear in their length. We further generalise these problems, by assuming that safety is defined only with respect to a subset of \emph{visible} edges. Here we prove a dichotomy between the $s$-$t$ paths and $s$-$t$ trails cases, and the $s$-$t$ walks case: the former two are NP-hard, while the latter is solvable with the same complexity as when all edges are visible. We also show that the same complexity results hold for the analogous generalisations of \emph{$s$-$t$ articulation points} (nodes appearing in all $s$-$t$ paths). We thus obtain the best possible results for natural"safety"-generalisations of these two fundamental graph problems. Moreover, our algorithms are simple and do not employ any complex data structures, making them ideal for use in practice.


Introduction
Connectivity and reachability are fundamental graph-theoretical problems studied extensively in the literature [12,16,9,20]. A key notion underlying such algorithms is that of edges (or nodes) critical for connectivity or reachability. The most basic variant of these are bridges (or articulation points), which are defined as follows. A bridge of an undirected graph, also referred as cut edge, is an edge whose removal increases the number of connected components. Similarly, a strong bridge in a (directed) graph is an edge whose removal increases the number of strongly connected components of the graph. (Strong) articulation points are defined in an analogous manner by replacing edge with node. Special applications consider the notion of bridge to be parameterised by the nodes that become disconnected upon its removal [18,22]. Given a node s, we say that an edge is an s bridge (also referred as edge dominators from source s [18]) if there exists a node t that is no longer reachable from s when the edge is removed. Moreover, given both nodes s and t, an s-t bridge is an edge whose removal makes t no longer reachable from s.
From this point onward we assume a fixed (directed) graph G without multiedges, with n nodes and m edges, and two given nodes s and t of G. Since s-t bridges are exactly the edges (i.e., the paths of length one) appearing in all s-t paths, it is natural to generalise this notion by considering the paths (i.e., of length two or more) appearing in all s-t paths. An equivalent way of defining this problem is through the notion of safety [23,24]. Given a set of walks W, we say that a walk W is safe with respect to W if W is a subwalk of all walks in W. Our problem is obtained by taking W to be the set of all s-t paths. 1 We will also consider other natural generalisations for W, e.g. all s-t trails and all s-t walks, as we will discuss in Subsection 1.1.
Motivation. Safety is motivated by real-world problems whose computational formulation admits multiple solutions. For this reason, we will also refer to the set W as the candidate set. By looking at the parts common to all solutions-the safe parts-one can make more informed guesses on what can be correctly reported from the data. This approach is more feasible than e.g., the common approach of simply enumerating all solutions.
A notable example is the genome assembly problem from Bioinformatics: one is given a set of short genomic fragments (the reads) and one needs to reconstruct the genome from which these were sequenced (see e.g. [19] for more details). A common approach is to build a graph from the reads, called the genome graph, and then to define a genome assembly solution as a certain type of walk in that graph. Practical assemblers do not assemble full genomes, because the genome graph may admit a large number of solutions, but instead efficiently output only shorter strings that are guaranteed to appear in the genome.
A natural notion of a genome assembly solution is that of a circular walk in the genome graph covering every edge or node at least once [23,24]. Finding all maximal safe walks for the edge-centric solution set can be solved optimally: an optimal quadratic-time algorithm was given in [6], and an optimal output-sensitive algorithm was given in [7]. In this paper we drop both the circularity and the covering requirements from this solution set. This yields more basic graph problems with more fundamental solution sets that can potentially be computed more efficiently in practice. In addition, we introduce a novel generalisation of the problems that makes a subset of nodes and edges invisible in the solution set. This models scenarios where we want to ignore some uncertain or complex parts of the graph, but still report if the walks flanking this region always appear as consecutive in any solution. Moreover, keeping them in the graph still allows them to impact the safety of other walks. As such, our problems also have potential applications to the practical genome assembly problem (see also Section 7).
Related work. Safety has several precursors, the closest being persistence: an individual node or edge is called persistent if it appears in all solutions to a problem on the given graph. Persistent nodes and edges have been studied for maximum independent sets [17], maximum bipartite matchings [10], assignments and transportations [8]. Other previous notions include d-transversals [11] (sets of nodes or edges intersecting every solution to the problem in at least d elements), d-blockers [25] (sets of nodes or edges whose removal deteriorates the optimum solution to the problem by at least d), or most vital nodes or edges [2].
For undirected graphs, the classical algorithm by Tarjan [21] computes all bridges and articulation points in linear time. However, for directed graphs only recently Italiano et al. [18] presented an algorithm to compute all strong bridges and strong articulation points in linear time. They also showed that classical algorithms [22,15] compute s bridges in linear time. The s articulation points (or dominators) are extensively studied resulting in several linear-time algorithms [1,4,3]. The s-t bridges were studied as minimum s-t cuts in network flow graphs, where an s-t bridge is a cut of unit size. These cuts can be discovered iteratively in the residual graph of the classic Ford Fulkerson algorithm [13] after pushing unit flow into the network. Contracting the first cut to s, the next s-t bridge can be discovered, and so on. Since only unit sized flows are of interest, the algorithm completes in linear time. Recently, this algorithm was simplified for unit sized cuts (s-t bridges) by Cairo et al. [5].

Problems Studied
Apart from the candidate set made up of all s-t paths (mentioned in the previous section), we will also consider two basic generalisations of it: the set of all s-t trails (i.e., walks from s to t which can repeat nodes, but not edges), and the set of all s-t walks (i.e., walks from s to t, which can repeat both nodes and edges). We denote the problems of computing the maximal safe walks (in terms of alternating sequences of nodes and edges) for each of these problems as MaxSafe followed by stPaths, stTrails, and stWalks, respectively.
In Figure 1, we present examples for these problems. Neither of the coloured cycles can be used by an s-t path, therefore the whole thick blue line is safe in stPaths. In stTrails, nodes can be reused and hence the red cycle (defined later as trail breaker), makes only the thick red lines as safe. In stWalks, s-t bridges can be reused as well and hence the green cycle (defined later as walk breaker), makes only the thick green lines as safe. An alternative way to look at these problems is to define safety in terms of only nodes, instead of walks. We define the node sequence of a walk W as the sequence (i.e., string) corresponding to V obtained by reading the nodes of W in order. A sequence of nodes is safe if it is a substring of the node sequence of every walk in the candidate set. We denote the corresponding safety problems as MaxSafe followed by V -stPaths, V -stTrails, and V -stWalks, respectively. We alternatively refer to them as the V -visible problems, whereas the natural case is referred as G-visible. The solutions to these V -visible problems can be obtained by simply leaving out the edges of maximal safe walks of G-visible problems. But when extending to multigraphs, the node-centric trails problem becomes more involved, since it allows the repetition of a node sequence in a trail if and only if the node sequence is connected by multiedges (see Section 6).
Another dimension for generalising the above models is to assume also a visible subset X ⊆ V ∪ E of nodes and edges and to define safety while looking only at the sequence of visible nodes and edges. We denote these problems as MaxSafe followed by X-stPaths, X-stTrails, and X-stWalks, respectively (or X-visible problems). For example, we say that a sequence of nodes and edges in X is safe for the X-stWalks problem if it is a substring of the X-subsequence (subsequence of elements in X) of each s-t walk. Table 1 Computational complexity of the problems studied in this paper. len(S) denotes the total length of the solution. (*) denotes the complexity for graphs without multi-edges, for multigraphs the complexity of MaxSafe V -stPaths is O(m + n + len(S)).

Visibility MaxSafe stPaths MaxSafe stTrails MaxSafe stWalks
In this paper we characterise the complexity of all nine MaxSafe problems for graphs, and later extend our results to multigraphs. See Table 1 for a summary of these results. The V -visible problems are an interesting special case of the X-visible problems, as they are solvable in linear time even though they restrict visibility. This is a useful observation, as genome assembly problems are often modelled with a node-centric graph [23,24].

Overview of our Approach
We solve all the linearly solvable MaxSafe problems with a similar algorithmic approach. Observe that a non-empty walk is uniquely defined by a sequence of edges. Therefore, we can simplify the G-visible and the V -visible problems to separately computing the maximal safe edge sequences (analogue to node sequences) and the maximal safe empty walks (i.e. that consist of a single node). To obtain the solutions of the G-visible problems, it then suffices to complete the edge sequences with their corresponding nodes. And to obtain the solutions of the V -visible problems, observe that a sequence of nodes is safe if and only if it spells out the nodes of a safe walk. Therefore we take the solution of the corresponding G-visible problem and remove the edges. This separation has the advantage that for the more complex graph structures that govern the safety of non-empty walks we only need to consider edges, and adding back the nodes in the end is trivial. Moreover, if we are only interested in safe sequences of edges, we simply skip adding the nodes. Using a simple graph transformation, the MaxSafe X-stWalks can also be solved by considering only edges.
Observe that for a sequence of edges to be safe in our models, each edge needs to be safe on its own. Therefore, a safe sequence can only contain visible s-t bridges, which we compute as the first step. This bridge sequence acts as the core of our solution, in the way that we can always describe the solution as a set of substrings of the bridge sequence, such that each s-t bridge is part of at least one maximal safe sequence. The bridge sequence (and similarly the articulation sequence) can be computed with the classical min-cut algorithm [13]. This algorithm was recently simplified for s-t bridges (or s-t articulation points) by Cairo et al. [5].
The second step of our algorithms is to compute certain breaking structures (as shown in Figure 1) that determine which substrings of the bridge sequence are maximal safe. For stPaths and stTrails and their V -visible counterparts, the breaking structures do not cause solutions to overlap. Since the length of the bridge sequence is in O(n) and the breaking structures that define non-overlapping solutions are simple, we obtain the following result. When extending to stWalks, we get more complex breaking structures that both overlap themselves and cause the solutions to overlap. This poses two problems. First, there can be up to O(n 2 ) of these breaking structures (see Figure 5), and the total length of the solution can be up to O(n 2 ) (see Figure 6). To handle the high amount of breaking structures, we show that they can be reduced to a dominating set of size O(n), which can be computed in O(m + n) time without computing all breaking structures first. To handle the solution length, we make use of the bridge sequence B. We show that there are at most O(|B|) maximal safe sequences, which allows us to represent the whole solution in a compact representation which can be unpacked in output-sensitive linear time(time linear in output size). This representation consists of the bridge sequence and the start and end indices of each maximal safe sequence. Its total size is O(|B|), and since each bridge is safe it never exceeds the total length of the solution. We show that this data structure can be computed in O(m + n) time. In contrast to this, when considering subset visibility for stPaths and stTrails, the respective safety problems are NP-hard. We prove that by reducing from the Detour problem of finding a u-v path passing through a third given node w (see Problem 14) which is known to be NP-hard. The reduction is possible, since the problems forbid edge repetitions and with subset visibility we can focus on the nodes of the Detour instance.

Theorem 3.
The MaxSafe X-visible stPaths and stTrails problems are NP-hard, even when deciding the safety of a sequence of just two elements of X and restricting X to contain only nodes or only edges.
Organisation of the paper. We describe the results in an incremental manner, gradually building upon the previous solution to solve harder problems. In the remaining subsections of this section we define our notation and describe some preliminary results including the s-t bridge algorithm. In Section 2 we describe how the s-t bridge algorithm can be expanded to solve MaxSafe stPaths and MaxSafe stTrails. In Section 3 we describe another algorithm that can be used on top of the s-t bridge algorithm to solve MaxSafe stWalks. As stated above, solving these problems also solves all V -visible problems. In Section 5 we describe how that algorithm can be expanded to solve MaxSafe X-stWalks. In Section 6 we describe how to extend our results to multigraphs. In Section 7 we review our results.

Notation
As defined above, we assume a fixed graph G := (V, E), where V is a set of n nodes and E a set of m edges. Furthermore, we assume two nodes s, t ∈ V are given. A graph is directed and may include loops, but not multiedges. A graph with multiedges is a multigraph. Given a set of nodes and edges X ⊆ V ∪ E, or a single node or edge X, then G[X] denotes its induced subgraph and G − X is the result of removing from X all edges and nodes (together with their incident edges). If X contains only edges, we may also write G \ X.
Given an edge e = (u, v), head(e) = v denotes its head and tail(e) = u denotes its tail. Given a sequence, a subsequence is obtained by removing arbitrary elements, while a substring is obtained by removing a prefix and a suffix (both possibly empty). A sequence if it contains only one node and non-empty otherwise. A walk W contains a sequence of edges (or nodes), if that sequence is a substring of its edge sequence (or node sequence).
The node expansion of a node v is an operation that transforms G into a graph G by adding a node v and an edge e v from v to v and moving all out-edges from v to v . We call e v the internal edge of v. Figure 2a), and all s-t bridges in B appear on every s-t path in G. Further, the s-t bridges in B demonstrate the following interesting property. Proof. It is sufficient to prove that for any b i ∈ B, all b j ∈ B (where j = i), can be categorised into those which are always visited before b i and those that are always visited after b i irrespective of the s-t path chosen in G. Consider the graph G \ b i , observe that every such b j is either reachable from s, or can reach t. It cannot fall in both categories as it would result in an s-t path in G \ b i , which violates b i being an s-t bridge. Further, it has to be in at least one category by considering any s-t path of G, where b i appears either between s and b j or between b j and t. Hence, those reachable from s in G \ b i are always visited before b i , and those able to reach t in G \ b i are always visited after b i , irrespective of the s-t path chosen in G.   Thus, abusing the notation, we define B to be a sequence of s-t bridges ordered by their visit time on any s-t path. Such a bridge sequence B implies an increasing part of the graph being reachable from s in G \ b i , as i increases. We thus divide the graph reachable from s into bridge components

Preliminaries
Additionally, for notational convenience we assume C |B|+1 to be the part of the graph reachable from s in G, but not in G \ b |B| (see Figure 2a). Since bridge components are separated by s-t bridges, every s-t path enters C i at a unique node (head(b i−1 ) or s for C 1 ) referred as its entrance. Similarly, it leaves C i at a unique node (tail(b i ) or t for C |B|+1 ) referred as its exit.
Similarly, the s-t articulation points are defined as the set of nodes A ⊆ V , such that removal of any s-t articulation point in A disconnects all s-t paths in G. Thus, The s-t articulation points in A also follow a fixed order in every s-t path (like s-t bridges), so A can be treated as a sequence and it defines the corresponding components C (see Figure 2b). Note that the entrance and exit of an articulation component C i are the preceding and succeeding s-t articulation points (if any), else s and t respectively.
The s-t bridges and articulation points along with their component associations can be computed in linear time, using either flows as described above, or the referenced simplification.

Safety for stPaths and stTrails
The s-t bridge algorithm (Theorem 5) is the main building block for proving Theorem 1.
Recall that we simplified the corresponding problems to only finding the maximal safe edge sequences. The solution to MaxSafe stPaths directly follows from the s-t bridge algorithm.
Observe that for two s-t bridges to form a safe sequence, they need to be adjacent. In the stPaths model, this is also sufficient, because visiting any other edge from the intermediate node would repeat the node to reach the latter edge (see the thick blue line in Figure 1). Therefore, we get the following characterisation. (⇐) Let L := (e 1 , . . . , e |L| ) be a substring of the bridge sequence such that each consecutive pair of edges is adjacent. Let W be an s-t path and W E its E-subsequence. We prove that L is a substring of W E by induction. For the base case, note that W E contains e 1 since L is made of strong s-t bridges. For the inductive step, assume that W E contains (e 1 , . . . , e i ) as substring. Since L is a substring of the bridge sequence, W contains e i+1 after e i . And since head(e i ) = tail(e i+1 ) and W is a path, it contains e i+1 immediately after e i .
Since each s-t path is an s-t trail, adjacency is still necessary for safety of stTrails, but not sufficient. In Figure 1, the s-t trail that uses the red cycle breaks the safe stPaths (thick blue line). Thus, such a red cycle or the non-adjacency of s-t bridges makes a trail breaker.  Any path P which is a trail breaker for a sequence (b i , b i+1 ) lies completely within the bridge component C i+1 . Otherwise, P would also contain either b i or b i+1 , which is not allowed. Note also that P is a cycle if head(b i ) = tail(b i+1 ). See Figure 3a for an illustration of a circular trail breaker and Figure 3b for a non-circular one. We get the following characterisation.

Theorem 8 (Safety for stTrails). A substring of the bridge sequence is safe under the stTrails model, if and only if it has no trail breaker.
Proof. (⇒) Let L be a substring of the bridge sequence that is safe under the stTrails model. Assume for a contradiction that L contains a trail breaker P from head(e i ) to tail(e i+1 ) for some i ∈ {1, . . . , |L| − 1}. As such, P is completely inside a bridge component C (the one with exit tail(e i+1 )). It holds that any s-t trail W (which contains L as substring, because L is safe) does not contain any edge from C. As a result, we can insert P in W between head(e i ) and tail(e i+1 ) to obtain an s-t trail W that does not contain L. This contradicts the safety of L.
(⇐) Let L := (e 1 , . . . , e |L| ) be a substring of the bridge sequence that has no trail breaker. Let W be an s-t trail and let W E be the E-subsequence of W . We prove that L is a substring of W E by induction. Note that W E contains e 1 , by assumption. For the inductive step, suppose that W E contains (e 1 , . . . , e i ) as substring. Since L is a substring of the bridge sequence, W E contains e i+1 after e i . And since L has no trail breaker, each non-empty head(e i )-tail(e i+1 ) path P contains e i or e i+1 . But e i is already used by W on the way to head(e i ), and e i+1 needs to be used to reach t from tail(e i+1 ). So no such P can be a subwalk of W , and thus e i is immediately followed by e i+1 in W E .
Using these characterisations, the s-t bridge algorithm can be directly used to solve the problems. After computing the s-t bridges and bridge components, the bridge sequence is split between non-adjacent pairs of consecutive s-t bridges, solving MaxSafe stPaths. For MaxSafe stTrails, the residual pairs of consecutive s-t bridges are checked for a trail breaker by checking if there is an incoming edge to tail(b i ) from a node in C i . Thus, both problems can be solved in O(m + n) time, proving Theorem 1.

Safety for stWalks
Unlike the previous problems, solving MaxSafe stWalks requires another algorithmic building block. Again, since each s-t trail is an s-t walk, the absence of trail breakers is necessary for safety for stWalks, but not sufficient. In Figure 1, an s-t walk using the green cycle breaks the thick red line that is safe in stTrails. Thus, such a green cycle or a trail breaker makes a walk breaker.

Definition 9 (Walk Breaker).
A walk breaker is a path that connects two consecutive s-t bridges e i , e i+1 from a substring L of the bridge sequence for i ∈ {1, . . . , |L| − 1} without using the first or last edge from L. Walk breakers can stay within a single bridge component (like trail breakers, recall Figure 3), but can also include multiple bridge components (see Figure 4). Characterisation for stWalks. Since a walk breaker P contains neither the first or last edge of its corresponding substring L of the bridge sequence, it contains no prefix or suffix of L. Therefore, if P is inserted into an s-t path that contains L, then the result contains a prefix and a suffix of L that together spell L, but that are interrupted by a subwalk that neither completes a prefix or suffix nor contains L itself. Thus, P contradicts the safety of L.
On the other hand, if it is possible to construct an s-t walk W that does not contain L, then W contains a last occurrence of e 1 , the first s-t bridge of L. After this last occurrence of e 1 , W contains a non-empty subwalk W between a pair of consecutive s-t bridges e i , e i+1 from L that does not contain e i+1 or e 1 . Therefore, W is a trail breaker for L. Resulting, we get a characterisation, using the following two lemmas required for its proof. Proof. We first prove that the minimal walk breaker contains a single backward edge by contradiction. Assume it contains multiple backward edges e 1 , ..., e k in order. Now consider a walk breaker using only the backward edge e 1 , clearly its bridge sequence is a substring of the bridge sequence of the original walk breaker and hence dominates it. Now, to complete the walk breaker we require tail(e) to be reachable from head(b j ) and tail(b i ) to be reachable from head(e). Since e originates from C j+1 with its entrance head(b j ) we can reach tail(e). The later case is ensured by the algorithm by marking only those nodes in C i which can reach tail(b i ). Finally, if the edge e ends in C i , it cannot start in a different bridge component C k . If k < i then walk breaker would contain an s-t bridge before b i ; symmetrically also k ≥ j holds. If k ∈ {i + 1, . . . , j}, then there exists a walk breaker that starts in b i and ends in b k−1 , which contradicts the minimality of the walk breaker, ensuring that e starts in C j . Lemma 11. Given the ordered set of minimal walk breakers P = {P 1 , P 2 , ..., P k } in the stWalks, a maximal safe sequence begins with b 1 and ends with b |B| if P = ∅, and otherwise either: (a) starts with b 1 and ends with the end of P 1 , or (b) ends with b |B| and starts with the start of P k , or (c) starts with the start of P i and ends with the end of P i+1 for some i ∈ {1, . . . , k − 1}.
Proof. The case where P = ∅ is trivial. Otherwise, let L be a maximal safe sequence. If L starts with an s-t bridge other than b 1 that is not the start of a minimal walk breaker, then it can be extended to the left without becoming unsafe, contradicting its maximality. By symmetry, L cannot end with an s-t bridge other than b |B| that is not the end of a minimal walk breaker. Therefore, the start and end s-t bridges considered in (a) -(c) are sufficient. It remains to prove that the pairings are correct.
(a) If L starts with b 1 , then it needs to end no later than the end of P 1 , since otherwise it would be proven unsafe by P 1 . It can end no earlier, since no walk breaker ends before P 1 . (b) If L ends with b |B| , then by symmetry with (a) it starts with P k . (c) If L starts with the start of P i for some i ∈ {1, . . . , k − 1}, then it cannot end after the end of P i+1 , since otherwise it would be proven unsafe by P i+1 . Furthermore, if it ends in the end of P i+1 , then it is neither proven unsafe by P i nor by P i+1 . And, since P is ordered, it is also not proven unsafe by another walk breaker. As such, L ends with the end of P i+1 .

Theorem 12 (Safety for stWalks). A substring of the bridge sequence is safe under the stWalks model, if and only if it has no walk breaker.
Proof. (⇒) Let L be a substring of the bridge sequence that is safe under the stWalks model. If there is a walk breaker for L, then from an s-t walk W an s-t walk W can be constructed by inserting the walk breaker into every occurrence of L. But then, L is not a substring of W .
(⇐) Let L := (e 1 , . . . , e |L| ) be a substring of the bridge sequence that has no walk breaker. Let W be an s-t walk and let W E be its E-subsequence. Since L is a substring of the bridge sequence, W E contains a substring W E that starts from the last occurrence of e 1 and ends in the first occurrence of e |L| after that, and L is a subsequence of W E . We prove that L is a prefix of W E by induction. By definition, W E starts with e 1 . For the inductive step, suppose that (e 1 , . . . , e i ) is a prefix of W E . By definition of W , none of its head(e i )-tail(e i+1 )-subwalks contain e 1 or e |L| . Therefore, since L does not have any walk breaker, e i+1 immediately follows e i in W E .

Computing Walk Breakers Efficiently
Since walk breakers can span over multiple bridge components, their structure is more complex than that of trail breakers. But as with trail breakers, the only edges of the walk breaker that are relevant, are the s-t bridges. Moreover, since walk breakers cannot skip s-t bridges they always correspond to a substring of the bridge sequence, where walk breakers with same substrings are equivalent. We refer to this substring as the bridge sequence of the walk breaker, and call its first edge the start and its last edge the end of the walk breaker. If a walk breaker that connects b i to b i+1 , i ∈ {1, . . . , |B| − 1} contains no s-t bridge (i.e. it is equivalent to a trail breaker), then we call b i+1 its start and b i its end. We call the amount of s-t bridges in the bridge sequence of a walk breaker its bridge length.
Minimal walk breakers. Given s and t, in the worst case, a graph may contain up to Θ(n 2 ) different walk breakers; see Figure 5 for an example. In this graph, there are |B| − i − 1 walk breakers of bridge length i, for each i ∈ {0, . . . , |B| − 2}. However, if the bridge sequence of a walk breaker is a substring of the bridge sequence of another walk breaker, every walk proven unsafe by the later is also proven unsafe by the former, i.e., the former dominates the later. Hence, computing all walk breakers is wasteful and we only focus on inclusion-minimal walk breakers, referred as minimal walk breakers which are only dominated by themselves.
With this notion of domination, it suffices to compute the set of minimal walk breakers in the graph to exclude all the unsafe walks. Note that at most one minimal walk breaker starts and ends at each s-t bridge, otherwise one would dominate the other. Therefore, there are at most O(|B|) different minimal walk breakers for a bridge sequence B. We now describe how to compute these in linear time.

Return Sol
Algorithm. Using s-t bridges and trail breakers (zero bridge length walk breakers) computed earlier, we now compute the minimal walk breakers of non-zero bridge length in two stages. First, we compute the O(|B|) walk breakers that are minimal with respect to their starts. Then we remove the dominated walk breakers to get the globally minimal walk breakers.
In the first stage, we start by performing backwards traversals from t and the tail of each s-t bridge that stay within the bridge component they started. This way, we mark each node that is reverse reachable from the exit of its bridge component. Now, all the walk breakers minimal from their start correspond to backward edges e of the following form: an edge from C j to C i (i < j) where head(e) is marked. Intuitively, a minimal walk breaker contains a single backward edge, because if it has multiple backward edges its minimality would be disproven by one of its backwards edges. The marked nodes ensure that walk breaker is completed by reaching the start (see Lemma 10). Hence, we iterate over all such edges and maintain the dominating walk breaker starting from each s-t bridge.
In the second stage, we traverse the walk breakers in reverse order of their starts and remove those that do not end before their successor (in forward order), and hence are dominated by the successor. Both of these stages run in linear time, and hence we get the following theorem (see Algorithm 1 for the pseudocode). Compact representation of the solution. In contrast to the previous problems, solutions to MaxSafe stWalks might overlap. This allows the solutions' total length to be quadratic in the number of nodes (see Figure 6). Therefore, instead of reporting the solution directly, the algorithm creates a compact representation from which the complete solution can be reported in time linear to its total length. This representation consists of the bridge sequence, and the starts and ends of each maximal safe walk in the bridge sequence. Now, each such maximal safe sequence begins with the start of previous walk breaker (or the first s-t bridge) and ends with the end of current walk breaker (or the last s-t bridge) (see Lemma 11). Note that the definition of the start and end for zero bridge length walk breakers (trail breakers) perfectly fits this structure of the solution. Hence, the indices of the solution for the compact representation can be computed by simply iterating over all minimal walk breakers, requiring O(|B|) time.
Resulting, the minimal walk breakers and the compact representation of the solution of size O(|B|) can be computed in O(m + n) time, which can be expanded to get the complete solution in time linear in the size of the solution. Thus, we have proven Theorem 2 for X = V ∪ E, X = V and X = E.

Subset Visibility
In this section, we discuss X-visible variants of our problems. We prove that MaxSafe X-stPaths and MaxSafe X-stTrails are in fact NP-hard (Theorem 3). We then show how to solve MaxSafe X-stWalks as an extension of MaxSafe stWalks.

NP-hardness.
We prove MaxSafe X-stPaths and MaxSafe X-stTrails to be NPhard by reduction from the following problem, proven NP-complete in [14,Theorem 2].

Problem 14 (Detour). Given a graph G and pairwise distinct nodes u, v, w of G, decide if there is a u-v path in G that contains w.
Observe that with the following reduction, a certificate for the unsafety of a sequence is also a certificate for a detour. Therefore, as Detour is in NP, our NP-hard problems are in co-NP. Formally, we describe it as follows.
Theorem 3. The MaxSafe X-visible stPaths and stTrails problems are NP-hard, even when deciding the safety of a sequence of just two elements of X and restricting X to contain only nodes or only edges.
Proof. Let G, u, v, w be an instance of Detour. In order to address the stTrails problem in the same way as the stPaths problem, we transform G into the graph G by expanding each node. For a node x we denote its internal edge as e x .
For the rest of the proof we set s = head(e u ) and t = tail(e v ). Every node of G has either exactly one incoming edge or exactly one outgoing edge (i.e., some internal edge e x ). As such, any s-t walk visiting a node twice also visits some edge twice (i.e., some internal edge e x incident to this repeated node of G ). Thus, all s-t trails of G are s-t paths.
When we restrict X ⊆ E, we set X = {e u , e w , e v }. We have that (e u , e v ) is safe under the X-visible s-t paths model in G if and only if G, u, v, w is a no-instance for Detour. Since all s-t trails of G are s-t paths, the same holds also for the s-t trails model.
When we restrict X ⊆ V , we set X = {s, tail(e w ), t}, and analogously have that (s, t) is safe under the S-visible s-t paths model in G , or under the s-t trails model in G , respectively, if and only if G, u, v, w is a no-instance for Detour.
When considering walks, both nodes and edges can be used without limits, and therefore the reduction from Detour does not work. Instead, our algorithm for MaxSafe stWalks can be extended to solve MaxSafe X-stWalks.
Characterisation for X-stWalks. In MaxSafe X-stWalks an additional subset X ⊆ V ∪ E of visible nodes and edges is given. By expansion of each visible node v and making its internal edge visible instead of v, we reduce the problem to X ⊆ E. Similar to previous problems, the solutions to MaxSafe X-stWalks are then substrings of the X-bridge sequence, which is the X-subsequence of the bridge sequence. Such a substring is safe if it contains no X-walk breaker, which is a walk breaker with an X-edge. With these definitions we get the following characterisation.

Theorem 15 (Safety for X-stWalks). A substring of the X-bridge sequence is safe under the X-stWalks model, if and only if it has no X-walk breaker.
Proof. (⇒) Let L be a substring of the X-bridge sequence that is safe under the X-stWalks model where X ⊆ E. If L has an X-walk breaker, then from an s-t walk W an s-t walk W can be constructed by inserting that X-walk breaker into every occurrence of L in the F -subsequence of W . But then L is not a substring of the F -subsequence of W .
(⇐) Let L := (e 1 , . . . , e |L| ) be a substring of the X-bridge sequence that has no X-walk breaker. Let W be an s-t walk and let W X be its X-subsequence. Since L is a substring of the X-bridge sequence, W X contains a substring W X that starts from the last occurrence of e 1 and ends in the first occurrence of e |L| after that, and L is a subsequence of W X . We prove that L is a prefix of W X by induction. By definition, W X starts with e 1 . For the inductive step, suppose that e 1 , . . . , e i is a prefix of W X . By definition of W , none of its head(e i )-tail(e i+1 )-subwalks contain e 1 or e |L| . Therefore, since L does not have any F -walk breaker, no e i -e i+1 -subwalk of W contains an X-edge. Thus e i is immediately followed by e i+1 in W X .
From this we can derive an algorithm similar to that for MaxSafe stWalks. After computing the bridge sequence and components, we remove those s-t bridges that are not in X and merge the corresponding bridge components. Then X-walk breakers of non-zero bridge length can be computed as before, since their s-t bridge is their X-edge. X-walk breakers of bridge length zero can be found by computing the reverse reachability from t as in Section 3, and then iterating over each X-edge of a bridge component and checking whether its head is marked. The rest of the algorithm remains unchanged. This algorithm runs in the same time constraints as that for MaxSafe stWalks.

Extension to Multigraphs
Most of the results in this paper can be applied to graphs with multiedges without much change. The s-t bridge algorithm naturally extends to multiedges. Since including multiedges is a generalisation, the NP-hardness results remain valid. Even for the G-visible problems and the X-stWalks problem no change is required. In V -stPaths and V -stWalks, where the multiplicity of edges is not relevant, the parallel edges can simply be merged. Only in V -stTrails extending to multigraphs (denoted by V -stMTrails) is non-trivial, as merging parallel edges changes the set of candidate solutions. See for example Figure 7, where adding a multiedge in a safe sequence of nodes creates a breaking structure.

Figure 7
Example for creating a trail breaker by adding a multiedge. Originally, the dashed edge cannot be used as a trail breaker without repeating the edge e. On adding the parallel edge e , the red cycle becomes a trail breaker repeating ai and ai+1 without repeating an edge. The blue regions mark articulation components and each node is an s-t articulation point.
To describe how to solve MaxSafe V -stMTrails, we now assume that G := (V, E) is a multigraph, G is G with all parallel edges merged and s, t ∈ V are given as before. First of all, observe that for a sequence of nodes to be safe in V -stMTrails, it needs to be a substring of the articulation sequence. Furthermore, we have a trivial necessary condition for safety, which is similar to the adjacency condition in the G-visible cases. A sequence of two nodes can only be safe if there is no path with more than one edge that connects the first to the second. This is equivalent to requiring that the two nodes are connected by an s-t bridge in G. From here on, we consider a sequence of nodes L that fulfils both of these conditions, where the second is fulfilled by each consecutive pair of nodes.
Let P be the path spelled by L, such that the edges of P are a substring of the bridge sequence. Such a P is safe in stPaths in G, and hence we can state that: for L to be safe also in V -stMTrails in G , it needs to spell out a path in G that is safe in stPaths. But we can make even more detailed relations to the G-visible cases.
For that, we denote the set of s-t trails in G as T , the set of s-t trails in G as T , and the set of s-t walks in G as W. We furthermore denote with V (T ), V (T ) and V (W) the sets of node sequences associated with these sets of walks, respectively. That is, V (T ) is the candidate set of V -stMTrails in G and V (T ) and V (W) are the candidate sets of V -stTrails and V -stWalks in G. Observe that we have the following relations: Therefore, if L is safe for V (T ), each element of V (T ) contains L, and therefore each element of V (T ) contains L as well, which makes L safe for V (T ). The same argument makes L safe for V (T ) if it is safe for V (W). With these relations, we can detail our statement from above by stating that: (a) For L to be safe in V -stMTrails in G , it needs to be safe in V -stTrails in G (because of the first inclusion in Equation (1)). This is equivalent to L spelling out a path in G that is safe in stTrails. (b) If L is safe in V -stWalks in G (which is equivalent to L spelling out a path in G that is safe in stWalks), then L is safe in V -stMTrails in G (because of the second inclusion in Equation (1)).
So, to compute the solutions of MaxSafe V -stMTrails that are not single nodes, we can start from the bridge sequence in G and proceed similarly to the G-visible cases. From statement (A), we know that trail breakers in G are breaking, while no other structure than a walk breaker in G can be breaking because of statement (B). Therefore, the question that remains is: what walk breakers in G of non-zero bridge length are actually breaking? To answer this question, observe that a walk breaker in G that contains an edge that is an s-t bridge in G cannot be used by an s-t trail in G without repeating that edge. All other walk breakers can be defined as follows.
Definition 16 (Trail Multi-Breaker). Let G be a multigraph and G be the graph obtained by merging the parallel edges of G . We say that Q is a trail multi-breaker in G if Q is a walk breaker in G that contains no s-t bridge of G .
We can prove that these are exactly the breaking structures in V -stMTrails. Consider a trail multi-breaker Q that is a walk breaker of non-zero bridge length for P . Let P be the set of all parallel edges of P in G (in addition to the edges of P ). Let R be an s-t path in G . It holds that Q and R can only share edges in P , since otherwise Q would not be a walk breaker for P . And since Q contains no edge that is an s-t bridge in G , all shared edges are not s-t bridges. Therefore, since merging all parallel edges in P produces the edges of P , which are s-t bridges, all edges that Q and R can share have a parallel edge. Replacing the shared edges with the parallel edges in R produces an s-t path in G in which Q can be inserted. Therefore, Q can be used by an s-t trail in G . Resulting, we get the following theorem.

Theorem 17. A substring L of the articulation sequence is safe under the V -stMTrails model if and only if it has no trail multi-breaker.
Hence, MaxSafe V -stMTrails can be solved by computing walk breakers in G, and filtering to keep only those whose bridge sequence contains no edge that is an s-t bridge in G . The solution can then be reported as for MaxSafe stWalks, and the whole algorithm runs in the same time constraints as MaxSafe stWalks.

Conclusions
On the theoretical side, we considered a natural generalisation of s-t bridges, with the notion of safety. We considered the standard solution sets of s-t paths, trails and walks, and natural extensions thereof. We fully characterised the complexity of all problems, obtaining a clear trichotomy between linearly solvable problems, problems that allow to compute a compact representation of the solution in linear time, and NP-hard problems.
On the practical side, our problems have potential applications in the genome assembly problem. Observe that, in a sense, our solution sets generalise the set W 0 of circular edgecovering walks, as follows. Take any edge e, and consider the set W e of all walks from the head of e to the tail of e. It holds that any safe walk w.r.t. W e is also safe w.r.t. W 0 .
But in contrast to circular models, our computational formulations can also be applied to non-circular genomes. Moreover, they can be applied to scenarios where more than one genome string (i.e. more chromosomes) has to assembled from a single genome graph, such as when sequencing and assembling a human genome. Furthermore, since some parts of the graph may correspond to errors from the genome sequencing process, not all edges should be covered (i.e., explained) by the genome assembly solution, which motivates removing the edge-covering assumption. Moreover, uncertain or complex parts of the graph can be handled by the subset visibility models. For example, suspected errors can also be marked as invisible, hiding them in the solutions. Moreover, diploid genomes such as human contain a maternal and a paternal copy of the chromosomes. A position where the two copies differ creates a branch in the graph, and this might undesirably break some safe solutions. This motivates marking such areas as invisible, to still determine if their flanking regions are consecutive in all solutions to this model. As such, one can potentially obtain long safe sequences skipping over invisible parts. Finally, all algorithms given here are much simpler than the ones of [6,7] (especially when using the simplified s-t bridge algorithm [5]), and thus potentially more suitable for practical applications.