1 Introduction and motivation
Suppose that the mayor of a small town decides to make all the streets one-way in such a way that it is possible to get from any place to any other place without violating the orientations of the streets111The motivation for doing so is that the streets of the town are very narrow and thus it is a great hassle when two cars unexpectedly meet.. If initially all the streets are two-way then Robbins’ theorem  asserts that this can be done exactly when the corresponding graph is -edge connected. If, on the other hand some of the streets were already one-way in the beginning then the generalised Robbins’ theorem  states that it can be done exactly when the corresponding graph is strongly connected and the underlying graph is -edge connected.
However, the proofs of both of these results assume that every street of the city corresponds to exactly one edge in the graph. This assumption hardly holds in any city in the world and therefore a much more natural assumption is that every street corresponds to a trail in the graph and that the edges of each trail must be oriented consistently222This version of the problem was given to us through personal communication with Professor Robert E. Tarjan.
In this paper we prove that Robbins’ Theorem continues to hold even when the set of edges is partitioned into trails. In other words a necessary and sufficient condition for an orientation to exist is that the graph is -edge connected. We also provide a linear time algorithm for finding such an orientation.
Finally we will consider the generalised Robbins’ theorem in this new setting i.e. we allow some edges to be oriented initially and suppose that the remaining edges are partitioned into trails. We will show that if any cut in the graph has either at least undirected edges going between to or a directed edge in each direction then it is possible to orient the trails making the resulting graph strongly connected. Although this condition is not necessary it does give a simple algorithm for deciding the problem. Indeed, the only cuts containing an undirected edge which we allow are the ones where this edge (and hence its trail) is forced in one direction. Hence for deciding the problem we can start by orienting all the forced trails until there are no more forced trails. Then the trails can be oriented making the graph strongly connected exactly if the resulting graph satisfies our condition.
Note that when some edges are initially oriented the answer to the problem depends on the trail decomposition which is not the case for the other results. That the condition from the generalised Robbins’ theorem is not sufficient can be seen from figure 1.
Several methods have already been applied for solving orientation problems in graphs where the goal is to make the resulting graph strongly connected.
One approach used by Robbins  is to use that a -edge connected graph has an ear-decomposition. An ear decomposition of a graph is a partition of the set of edges into a cycle and paths such that has its two endpoints but none of its internal vertices on . Assuming the existence of an ear decomposition of -edge connected graphs it is easy to prove Robbins’ theorem. Indeed, it is easy to see by induction that any consistent orientations of the paths and the cycle give a strongly connected graph.
A second approach introduced by Tarjan  gives another simple proof of Robbins’ theorem. One can make a DFS tree in the graph rooted at a vertex and orient all edges in the DFS tree away from . The remaining edges are oriented towards and if the graph is -edge connected it is easily verified that this gives a strong orientation.
A similar approach was used by Chung et al.  in the context of the generalized Robbins theorem for mixed multigraphs.
The above methods not only prove Robbins’ theorem, they also provide linear time algorithms for finding strong orientations of undirected or mixed multigraphs.
However, none of the above methods have proven fruitful in our case. In case of the ear decomposition one needs a such which is somehow compatible with the partitioning into trails and this seems hard to guarantee. The original proof by Roberts is essentially similar to using the ear decomposition. Similar problems appear when trying a DFS-approach. Neither does the proof by Boesch  of Robbins’ theorem for mixed multigraphs generalise to prove our result. Most importantly the corresponding theorem is no longer true for trail orientations as is shown by the example above.
Since the classical linear time algorithms rely on ear-decompositions and DFS searches, and since these approaches do not immediately work for trail partitions, our linear time algorithm will be a completely new approach to solving orientation problems.
Let us briefly review the concepts from graph theory that we will need. Recall that a walk in a graph is an alternating sequence of vertices and edges , such that for the edge has and as its two endpoints. In a directed or mixed graph the ordering of the endpoints of each edge in the sequence must be consistent with the direction of the edge in case it is oriented. A trail is a walk without repeated edges. A path is a trail without repeated vertices (except possibly ). Finally a cycle is a path for which
Next, recall that a mixed multigraph is called strongly connected if for any vertices there exists a walk from to . In case that the graph contains no directed edges this is equivalent to saying that it consists of exactly one connected component.
We also recall the definition of -edge connectivity. A graph is said to be -edge connected if and only if is connected for all where . A trivially equivalent condition is that any edge-cut in the graph has at least edges going between and .
Finally, if is a mixed multigraph and we define to be that graph obtained by contracting to a single vertex and to be the subgraph of induced by . The following simple observation will be used repeatedly in this paper.
If is -edge connected and then is -edge connected. Also if is a strongly connected mixed multigraph then is too.
The structure of this paper is as follows. In section 3 we prove our generalisation of Robbins’ theorem for undirected graphs partitioned into trails. In section 4 we study what happens in the case of mixed graphs. Finally in section 5 we provide our linear time algorithm for trail orientation in an undirected graph.
3 Robbins Theorem Revisited
We are now ready to state our generalisation of Robbins’ theorem.
Let be a multigraph with partitioned into trails. An orientation of each trail such that the resulting directed graph is strongly connected exists if and only if is -edge connected.
If is not -edge connected, such an orientation obviously doesn’t exist so we need to prove the converse. Suppose therefore that is -edge connected.
Our proof is by induction on the number of edges in . If there are no edges, the graph is a single vertex, and the statement is obviously true. Assume now the statement holds for all graphs with strictly fewer edges than . Pick an arbitrary edge that is at the end of its corresponding trail.
If is -edge connected, then by the induction hypothesis there is a strong orientation of that respects the trails of . Such an orientation clearly extends to the required orientation of .
If is not -edge connected, there exists a bridge in (see figure 2). Let , be the two connected components of , and let and such that for , (note that we don’t necessarily have that and are distinct for ). Now for construct the graph , and define the trails in to be the trails of that are completely contained in , together with a single trail combined from the (possibly empty) partial trail of contained in and ending at , followed by the edge , followed by the (possibly empty) partial trail of contained in starting at . Both and are -edge connected since they can each be obtained as a contraction of . Furthermore, they each have strictly fewer edges than , so inductively each has a strong orientation that respects the given trails. Further, we can assume that the orientations are such that the new edges are oriented as and by flipping the orientation of all edges in either graph if necessary. We claim that this orientation, together with oriented as and oriented as , is the required orientation of . To see this first note that (by construction) this orientation respects the trails. Secondly suppose and are arbitrary. Since is strongly connected contains a directed path from to . Similarly, contains a directed path from to . Thus contains a directed path from to . A similar argument gives a directed path from to and since and were arbitrary this proves that is strongly connected and our induction is complete.
The construction in the proof can be interpreted as a naive algorithm for finding the required orientation when it exists.
The one-way trail orientation problem on a graph with vertices and edges can be solved in time, where is the time per operation for fully dynamic bridge finding (a.k.a. -edge connectivity).
At the time of this writing333Separate paper submitted to SODA’18 by Holm, Rotenberg and Thorup., this is . In Section 5 we will show a less naive algorithm that runs in linear time.
4 Extension to Mixed graphs
Now we will extend our result to the case of mixed graphs. We are going to prove the following.
Let be a strongly connected mixed multigraph. Then is strongly connected for all undirected if and only if for any partition of the undirected edges of into trails, and any , any orientation of can be extended to a strong trail orientation of .
Suppose is as in the theorem. We will say that is forced if it is undirected and satisfies that is not strongly connected444This terminology is natural since it is equivalent to saying that there exists a cut in such that is the only undirected edge in this cut and such that all the directed edges go from to . If one wants an orientation of the trails making the graph strongly connected we are clearly forced to orient from to .. Note that this is a proper extension of Theorem 2 since if is undirected and -edge connected then no is forced.
For proving the result we’ll need the following lemma.
Let be a directed graph, and let be a cut with exactly one edge crossing from to and at least one edge crossing from to . Then is strongly connected if and only if and are.
Strong connectivity is preserved by contractions, so if is strongly connected then and both are. For the other direction, let be the edge going from to , and let be any edge from to . Since is strongly connected and is the only edge from to , contains a path from to that stays in . Since this holds for any edge going from to , and since is strongly connected, is strongly connected in . By a symmetric argument, is also strongly connected in and since the cut has edges in both directions, must be strongly connected. ∎
Now we provide the proof of Theorem 4.
Proof of theorem 4.
If is not strongly connected, the trail containing can at most be directed one way since is forced, so there is an orientation of which not extend to a strong trail orientation of . To prove the converse suppose is strongly connected for all undirected .
The proof is by induction on . If the result is trivial. So suppose and that the theorem holds for all with .
Consider a trail . Suppose there is no cut that crosses exactly once, which has exactly one other undirected edge crossing it, and has every directed edge crossing it going from to . Then regardless of the orientation of , the resulting graph has no undirected edge such that is not strongly connected. Thus, by induction has a strong trail orientation, which is also a strong trail orientation of , as desired.
Now suppose there is such a cut (see figure 3). Construct a graph by contracting every vertex in into a single new vertex . Let consist of all trails in that are completely contained in , together with a single trail combined from the (possibly empty) fragments of the two trails that crossed the cut, joined at . Since any cut in corresponds to a cut in , is strongly connected and remains so after deletion of any single undirected edge. By induction any orientation of in extends to a strong orientation of . Let , , and be defined symmetrically, then by the same argument any orientation of in extends to a strong orientation of . Now for any orientation of , we can choose orientations of and that are compatible. The result follows by Lemma 5. ∎
Notice that the partitioning of edges into trails does not matter in the case when no edge is forced. Since any undirected graph has no forced edges if it is -edge connected, the theorem implies that the most naive algorithm: "directing trails that are forced and if none are forced direct an arbitrary trail" works for undirected graphs. In general for mixed graphs algorithm 1 below can clearly be implemented in polynomial time and does solve the trail orientation problem for mixed graphs.
Theorem 4 gives a sufficient condition for when a strong orientation exists and we deal with the other cases by dealing with the forced edges first. However, the generalised Robbins’ Theorem provides a simple equivalent condition, which we lack. Finding such an equivalent condition when you have trail decomposition is an essential open problem for strong graph orientations. Due to figure 1 in this setting one has to take into account the structure of the trail partition.
5 Linear time algorithm
In this section we provide our linear time algorithm for solving the trail orientation problem in undirected graphs. For this, we make two crucial observations. First, we show that there is an easy linear time reduction from general graphs or multigraphs to cubic multigraphs. Second, we show that in a cubic multigraph with vertices, we can in linear time find and delete a set of edges that are at the end of their trails, such that the resulting graph has -edge connected components. We further show that we can compute the required orientation recursively from an orientation of each -edge connected component together with the cactus of -edge connected components. Since the average size of these components is constant, we can compute the orientations of most of them in linear time. The rest contains at most a constant fraction of the vertices, and so a simple geometric sum argment tells us that the total time is also linear.
We start out by making the following reduction.
The one-way trail problem on a -edge connected graph or multigraph with vertices and edges, reduces in time to the same problem on a -edge connected cubic multigraph with vertices and edges.
Order the edges adjacent to each vertex such that two edges that are adjacent on the same trail are consecutive in the order. Replace each single vertex with a cycle of length , with each vertex of the new cycle inheriting a corresponding neighbour of . Note that for a vertex of degree , this creates a pair of parallel edges, so the result may be a multigraph. Since edges on the same trail are neighbours, we can make the cycle-edge between the two corresponding vertices belong to the same trail. The rest of the cycle edges form new length trails. This graph has exactly vertices and edges, and any one-way trail orientation on this graph translates to a one-way trail orientation of the original graph. The graph is constructed in time.
Recall now that a graph is called a cactus if it is connected and each edge is contained in at most one cycle. If is any connected graph we let be its -edge connected components. It is well known that if we contract each of these we obtain a cactus graph. For a proof of this result see section 2.3.5 of . As the cuts in a contracted graph are also cuts in the original graph we have that if is -edge connected then the cactus graph is -edge connected. The edges of the cactus are exactly the edges of which are part of a -edge cut. We will call these edges 2-edge critical.
It is easy to check that if a cactus has edges and vertices then . We will be using this result in the proof of the following lemma.
Let be a cubic -edge connected multigraph, let , and let be minimal such that is -edge connected. Then has at least distinct -edge connected components.
Let , be the set of edges deleted from to obtain , and let be the remaining edges in .
If , then by minimality of there are at least 2-edge-critical edges in i.e. edges of the corresponding cactus, and thus at least distinct -edge connected components.
If then , and since is cubic and the removal of each edge creates two vertices of degree we must have that has at least distinct -edge connected components. ∎
Let be a connected cubic multigraph with partitioned into trails. Then has a spanning tree that contains all edges that are not at the end of their trail.
Let be the set of edges that are not at the end of their trail. Since is cubic, the graph is a collection of vertex-disjoint paths, and in particular it is acyclic. Since is connected can be extended to a spanning tree. ∎
Note that we can find this spanning tree in linear time. Indeed, we may assign weight to edges in and to the remaining edges and use the so-called555Originally discovered by Jarník , later rediscovered by Prim  Prim’s minimal spanning tree algorithm with a suitable priority queue to find the tree.
Let be a cubic -edge connected multigraph with partitioned into trails. Let be a spanning tree of containing all edges that are not at the end of their trail. Let be a minimal subgraph of that contains and is -edge connected. Then for any , less than of the vertices in are in a -edge connected component with at least vertices.
Let be the set of edges that are not in . Since is cubic, . By Lemma 7 has at least -edge connected components. Each such component contains at least one vertex, so the total number of vertices in components of size at least is less than . ∎
Let be a -edge connected component in some graph , whose edges is partitioned into trails. Define to be the -edge connected graph obtained by replacing each min-cut where and and with a single new edge . Define the corresponding partition of the edges of into trails by taking every trail that is completely contained in , together with new trails combined from the fragments of the trails that were broken by the min-cuts together with the new edges that replaced them. See figure 5.
At this point the idea of the algorithm can be explained. We remove as many of the edges, at the end of their trails, as we can still maintaining that the graph is -edge connected. Lemma 9 guarantees that we obtain a graph with many -edge connected components of size . We solve the problem for each for every -edge connected component. Finally, we combine the solutions for the different components like in the proof of theorem 2.
The one-way trail orientation problem can be solved in time on any -edge connected graph or multigraph with vertices and edges.
By Lemma 6, we can assume the graph is cubic. For the algorithm we will use two subroutines. First of all when we have found the minimum spanning tree containing the edges that are not on the end of their trail we can use the algorithm of Kelsen  to, in linear time, find a minimal (w.r.t. inclusion) subgraph of that contains and is -edge connected. Secondly we will use the algorithm of Melhorn  to, in linear time, build the cactus graph of -edge connected components. The algorithm runs as follows:
Construct a spanning tree of that contains all edges that are not at the end of their trail.
Construct a minimal subgraph of that contains and is -edge connected666See Kelsen .
Find the cactus of -edge connected components of777See Melhorn  .
For each -edge connected component , construct .
Recursively compute an orientation for each888Note that is cubic unless it consists of exactly one node. In this case however we don’t need to do anything. .
Combine the orientations from each component.
First we will show correctness and then we will determine the running time.
Recall that we can flip the orientation in each and still obtain a strongly connected graph respecting the trails in . The way we construct the orientation of the edges of is by flipping the orientation of each in such a way that each cycle in the cactus graph becomes a directed cycle999In practise this is done by making a DFS (or any other search tree one likes) of the cactus and repeatedly orienting each component in a way consistent with the previous ones.. This can be done exactly because no edge of the cactus is contained in two cycles. By construction this orientation respects the trails so we need to argue that it gives a strongly connected graph.
For showing that the resulting graph is strongly connected, first let every -edge connected component be contracted, then the graph is strongly connected since the cycles of the cactus graph have become directed cycles. Now assume inductively that we have uncontracted some of the components and call this graph . Now we uncontract another component (see figure 6) and obtain a new graph which we will show is also strongly connected. If , then since is strongly connected there is a path from to in . If this path only contains edges which are edges in clearly this path also exists in so we are done. If the path uses one of the added edges (without loss of generality oriented from to ), it is because there are edges and forming a cut and thus being part of a cycle in the cactus. In this case we use edge to leave component and then go from back to component which is possible since was strongly connected. When we get back to the component we must arrive at since otherwise there would be two cycles in the cactus containing the edge . Hence the edge was not needed. This argument can be used for any of the edges of that are not in and thus we can move between any two nodes in . Since was strongly connected this suffices to show that is strongly connected. By induction this implies that after uncontracting all components the resulting graph is strongly connected.
Now for the running time. By Lemma 9 each level of recursion reduces the number of vertices in “large” components by a constant fraction, for instance for we reduce the number of vertices in large components by a factor of . Let be the worst case running time with nodes for a cubic graph, and pick large enough such that is larger than the time it takes to go through steps - and as well as computing the orientations in the “small” components. Let be the number of vertices in the “large” -edge connected components. Then and
Inductively we may assume that and thus obtain
proving that for all .
6 Open problems
We here mention two problems concerning trail orientations which remain open.
First of all, our linear time algorithm for finding trail orientations only works for undirected graphs and it doesn’t seem to generalise to the trail orientation problem for mixed graphs. It would be interesting to know whether there also exists a linear time algorithm working for mixed graphs. If so it would complete the picture of how fast an algorithm we can obtain for any variant of the trail orientation problem.
Secondly, our sufficient condition for when it is possible to solve the trail orientation problem for mixed multigraphs is clearly not necessary. It would be interesting to know whether there is a simple necessary and sufficient condition like there is in the undirected case. Since in the mixed case the answer to the problem actually depends on the given trail decomposition and not just on the connectivity of the graph it is harder to provide such a condition. One can give the following condition. It is possible to orient the trails making the resulting graph strongly connected if and only if when we repeatedly direct the forced trails end up with a graph satisfying our condition in theorem 4. This condition is not simple and is not easy to check directly. Is there a more natural condition?
-  Frank Boesch and Ralph Tindell. Robbins’s theorem for mixed multigraphs. The American Mathematical Monthly, 87(9):716–719, 1980.
-  Fan R. K. Chung, Michael R. Garey, and Robert E. Tarjan. Strongly connected orientations of mixed multigraphs. Networks, 15(4):477–484, 1985.
-  John Hopcroft and Robert Tarjan. Algorithm 447: Efficient algorithms for graph manipulation. Commun. ACM, 16(6):372–378, June 1973.
-  V. Jarník. O jistém problému minimálním: (Z dopisu panu O. Borůskovi). Práce Moravské přírodovědecké společnosti. Mor. přírodovědecká společnost, 1930.
-  Pierre Kelsen and Vijaya Ramachandran. On finding minimal 2-connected subgraphs. In Proceedings of the Second Annual ACM/SIGACT-SIAM Symposium on Discrete Algorithms, 28-30 January 1991, San Francisco, California., pages 178–187, 1991.
-  Kurt Mehlhorn, Adrian Neumann, and Jens M. Schmidt. Certifying 3-edge-connectivity. Algorithmica, 77(2):309–335, 2017.
-  Hiroshi Nagamochi and Toshihide Ibaraki. Algorithmic Aspects of Graph Connectivity. Cambridge University Press, New York, NY, USA, 1 edition, 2008.
-  R. C. Prim. Shortest connection networks and some generalizations. The Bell System Technical Journal, 36(6):1389–1401, Nov 1957.
-  H. E. Robbins. A theorem on graphs, with an application to a problem of traffic control. The American Mathematical Monthly, 46(5):281–283, 1939.