Parameterized complexity of finding a spanning tree with minimum reload cost diameter^{1}
Abstract
We study the minimum diameter spanning tree problem under the reload cost model (DiameterTree for short) introduced by Wirth and Steffan (2001). In this problem, given an undirected edgecolored graph , reload costs on a path arise at a node where the path uses consecutive edges of different colors. The objective is to find a spanning tree of of minimum diameter with respect to the reload costs. We initiate a systematic study of the parameterized complexity of the DiameterTree problem by considering the following parameters: the cost of a solution, and the treewidth and the maximum degree of the input graph. We prove that DiameterTree is paraNPhard for any combination of two of these three parameters, and that it is FPT parameterized by the three of them. We also prove that the problem can be solved in polynomial time on cactus graphs. This result is somehow surprising since we prove DiameterTree to be NPhard on graphs of treewidth two, which is best possible as the problem can be trivially solved on forests. When the reload costs satisfy the triangle inequality, Wirth and Steffan (2001) proved that the problem can be solved in polynomial time on graphs with , and Galbiati (2008) proved that it is NPhard if . Our results show, in particular, that without the requirement of the triangle inequality, the problem is NPhard if , which is also best possible. Finally, in the case where the reload costs are polynomially bounded by the size of the input graph, we prove that DiameterTree is in XP and W[1]hard parameterized by the treewidth plus .
Keywords: reload cost problems; minimum diameter spanning tree; parameterized complexity; FPT algorithm; treewidth; dynamic programming.
1 Introduction
Numerous network optimization problems can be modeled by edgecolored graphs. Wirth and Steffan introduced in [33] the concept of reload cost, which refers to the cost that arises in an edgecolored graph while traversing a vertex via two consecutive edges of different colors. The value of the reload cost depends on the colors of the traversed edges. Although the reload cost concept has many important applications in telecommunication networks, transportation networks, and energy distribution networks, it has surprisingly received attention only recently.
In heterogeneous communication networks, routing requires switching among different technologies such as cables, fibers, and satellite links. Due to data conversion between incompatible subnetworks, this switching causes high costs, largely outweighing the cost of routing the packets within each subnetwork. The recently popular concept of vertical handover [11], which allows a mobile user to have undisrupted connection during transitioning between different technologies such as 3G (third generation) and wireless local area network (WLAN), constitutes another application area of the reload cost concept. Even within the same technology, switching between different service providers incurs switching costs. Another paradigm that has received significant attention in the wireless networks research community is cognitive radio networks (CRN), a.k.a. dynamic spectrum access networks. Unlike traditional wireless technologies, CRNs operate across a wide frequency range in the spectrum and frequently requires frequency switching; therefore, the frequency switching cost is indispensable and of paramount importance. Many works in the CRNs literature focused on this frequency switching cost from an application point of view (for instance, see [3, 21, 4, 5, 14, 1, 31]) by analyzing its various aspects such as delay and energy consumption. Operating in a wide range of frequencies is indeed a property of not only CRNs but also other 5G technologies. Hence, applications of the reload cost concept in communication networks continuously increment. In particular, the energy consumption aspect of this switching cost is especially important in the recently active research area of green networks, which aim to tackle the increasing energy consumption of information and communication technologies [6, 8].
Reload cost concept finds applications also in other networks such as transportation networks and energy distribution networks. For instance, a cargo transportation network uses different means of transportation. The loading and unloading of cargo at junction points is costly and this cost may even outweigh the cost of carrying the cargo from one point to another [15]. In energy distribution networks, reload costs can model the energy losses that occur at the interfaces while transferring energy from one type of carrier to another [15].
Recent works in the literature focused on numerous problems related to the reload cost concept: the minimum reload cost cycle cover problem [17], the problems of finding a path, trail or walk with minimum total reload cost between two given vertices [20], the problem of finding a spanning tree that minimizes the sum of reload costs of all paths between all pairs of vertices [18], various path, tour, and flow problems related to reload costs [2], the minimum changeover cost arborescence problem [16, 25, 23, 22], and problems related to finding a proper edge coloring of the graph so that the total reload cost is minimized [24].
The work in [33], which introduced the concept of reload cost, focused on the following problem, called Minimum Reload Cost Diameter Spanning Tree (DiameterTree for short), and which is the one we study in this paper: given an undirected graph with an edgecoloring and a reload cost function , find a spanning tree of with minimum diameter with respect to the reload costs (see Section 2 for the formal definitions).
This problem has important applications in communication networks, since forming a spanning tree is crucial for broadcasting control traffic such as route update messages. For instance, in a multihop cognitive radio network where a frequency is assigned to each wireless link depending on availabilities of spectrum bands, delayaware broadcasting of control traffic necessitates the forming of a spanning tree by taking the delay arising from frequency switching at every node into account. Cognitive nodes send various control information messages to each other over this spanning tree. A spanning tree with minimum reload cost diameter in this setting corresponds to a spanning tree in which the maximum frequency switching delay between any two nodes on the tree is minimized. Since control information is crucial and needs to be sent to all other nodes in a timely manner, ensuring that the maximum delay is minimum is vital in a cognitive radio network.
Wirth and Steffan [33] proved that DiameterTree is inapproximable within a factor better than (in particular, it is NPhard), even on graphs with maximum degree . They also provided a polynomialtime exact algorithm for the special case where the maximum degree is and the reload costs satisfy the triangle inequality. Galbiati [15] showed stronger hardness results for this problem, by proving that even on graphs with maximum degree , the problem cannot be approximated within a factor better than if the reload costs do not satisfy the triangle inequality, and cannot be approximated within any factor better than if the reload costs satisfy the triangle inequality. The complexity of DiameterTree (in the general case) on graphs with maximum degree was left open.
Our results. In this article we initiate a systematic study of the complexity of the DiameterTree problem, with special emphasis on its parameterized complexity for several choices of the parameters. Namely, we consider any combinations of the parameters (the cost of a solution), (the treewidth of the input graph), and (the maximum degree of the input graph). We would like to note that these parameters have practical importance in communication networks. Indeed, besides the natural parameter , whose relevance is clear, many networks that model reallife situations appear to have small treewidth [27, 30]. On the other hand, the degree of a node in a network is related to its number of transceivers, which are costly devices in many different types of networks such as optical networks [29]. For this reason, in practice the maximum degree of a network usually takes small values.
Before elaborating on our results, a summary of them can be found in Table 1.
Problem  Parameterized complexity with parameter  Polynomial  

cases  

NPh for  NPh for  NPh for  FPT  in P on 
DiameterTree 
(Thm 5)  cacti  
(Thm 1)  (Thm 2)  (Thm 3)  (Thm 4)  
DiameterTree 
XP (Thm 5)  
with poly costs  W[1]hard  
(Thm 6) 
We first prove, by a reduction from 3Sat, that DiameterTree is NPhard on outerplanar graphs (which have treewidth at most 2) with only one vertex of degree greater than 3, even with three different costs that satisfy the triangle inequality, and . Note that, in the case where the costs satisfy the triangle inequality, having only one vertex of degree greater than 3 is best possible, as if all vertices have degree at most 3, the problem can be solved in polynomial time [33]. Note also that the bound on the treewidth is best possible as well, since the problem is trivially solvable on graphs of treewidth 1, i.e., on forests.
Toward investigating the border of tractability of the problem with respect to treewidth, we exhibit a polynomialtime algorithm on a relevant subclass of the graphs of treewidth at most 2: cactus graphs. This algorithm is quite involved and, in a nutshell, processes in a bottomup manner the block tree of the given cactus graph, and uses at each step of the processing an algorithm that solves 2Sat as a subroutine.
Back to hardness results, we also prove, by a reduction from a restricted version of 3Sat, that DiameterTree is hard on graphs with , even with only two different costs, , and bounded number of colors. In particular, this settles the complexity of the problem on graphs with in the general case where the triangle inequality is not necessarily satisfied, which had been left open in previous work [33, 15]. Note that is best possible, as DiameterTree can be easily solved on graphs with .
As our last hardness reduction, we prove, by a reduction from Partition, that the DiameterTree problem is hard on planar graphs with and .
The above hardness results imply that the DiameterTree problem is paraNPhard for any combination of two of the three parameters , , and . On the positive side, we show that DiameterTree is FPT parameterized by the three of them, by using a (highly nontrivial) dynamic programming algorithm on a tree decomposition of the input graph.
Since our parahardness reduction with parameter is from Partition, which is a typical example of weakly complete problem [19], a natural question is whether DiameterTree, with parameter , is paraNPhard, XP, W[1]hard, or FPT when the reload costs are polynomially bounded by the size of the input graph. We manage to answer this question completely: we show that in this case the problem is in XP (hence not parahard) and W[1]hard parameterized by . The W[1]hardness reduction is from the Unary Bin Packing problem parameterized by the number of bins, proved to be hard by Jansen et al. [26].
Altogether, our results provide an accurate picture of the (parameterized) complexity of the DiameterTree problem.
Organization of the paper. We start in Section 2 with some brief preliminaries about graphs, the DiameterTree problem, parameterized complexity, and tree decompositions. In Section 3 we provide the paraNPhardness results. In Section 4 we present the polynomialtime algorithm on cactus graphs, and in Section 5 we present the FPT algorithm on general graphs parameterized by . In Section 6 we focus on the case where the reload costs are polynomially bounded. Finally, we conclude the article in Section 7.
2 Preliminaries
Graphs and sets. We use standard graphtheoretic notation, and we refer the reader to [12] for any undefined term. Given a graph and a set , we define to be the set of edges of that intersect . We also define . For a graph and an edge , we let . Given a graph and a set , we say that is good for if each connected component of contains at least one vertex of . Given two integers and with , we denote by the set of all integers such that . For an integer , we denote by the set of all integers such that .
Reload costs and definition of the problem. For reload costs, we follow the notation and terminology defined by [33]. We consider edgecolored graphs , where the colors are taken from a finite set and the coloring function is . The reload costs are given by a nonnegative function , which we assume for simplicity to be symmetric. The cost of traversing two incident edges , is . By definition, reload costs at the endpoints of a path equal zero. Consequently, the reload cost of a path with one edge also equals zero. The reload cost of a path of length with edges is defined as . The induced reload cost distance function is given by . The diameter of a tree is , where for notational convenience we assume that the edgecoloring function and the reload cost function are clear from the context.
The problem we study in this paper can be formally defined as follows:
Minimum Reload Cost Diameter Spanning Tree (DiameterTree) Input: A graph with an edgecoloring and a reload cost function . Output: A spanning tree of minimizing .
If for every three distinct edges of incident to the same node, it holds that , we say that the reload cost function satisfies the triangle inequality. This assumption is sometimes used in practical applications [33].
Parameterized complexity. We refer the reader to [13, 9] for basic background on parameterized complexity, and we recall here only some basic definitions. A parameterized problem is a language . For an instance , is called the parameter.
A parameterized problem is fixedparameter tractable (FPT) if there exists an algorithm , a computable function , and a constant such that given an instance , (called an FPT algorithm) correctly decides whether in time bounded by . For instance, the Vertex Cover problem parameterized by the size of the solution is FPT.
A parameterized problem is in XP if there exists an algorithm and two computable functions and such that given an instance , (called an XP algorithm) correctly decides whether in time bounded by . For instance, the Clique problem parameterized by the size of the solution is in XP.
A parameterized problem with instances of the form is paraNPhard if it is NPhard for some fixed constant value of the parameter . For instance, the Vertex Coloring problem parameterized by the number of colors is paraNPhard. Note that, unless , a paraNPhard problem cannot be in XP, hence it cannot be FPT either.
Within parameterized problems, the class W[1] may be seen as the parameterized equivalent to the class NP of classical optimization problems. Without entering into details (see [13, 9] for the formal definitions), a parameterized problem being W[1]hard can be seen as a strong evidence that this problem is not FPT. For instance, the Clique problem parameterized by the size of the solution is the canonical example of a W[1]hard problem. To transfer W[1]hardness from one problem to another, one uses a parameterized reduction, which given an input of the source problem, computes in time , for some computable function and a function , an equivalent instance of the target problem, such that is bounded by a function depending only on .
Tree decompositions. A tree decomposition of a graph is a pair , where is a tree and is a collection of subsets of such that:

,

for every edge , there is a such that , and

for each such that lies on the unique path between and in , .
We call the vertices of nodes of and the sets in bags of . The width of the tree decomposition is . The treewidth of , denoted by , is the smallest integer such that there exists a tree decomposition of of width at most .
Nice tree decompositions. Let be a tree decomposition of , be a vertex of , and be a collection of subgraphs of , indexed by the vertices of . We say that the triple is nice if the following conditions hold:

and ,

each node of has at most two children in ,

for each leaf , and Such a is called a leaf node,

if has exactly one child , then either

for some and . The node is called vertexintroduce node and the vertex is the insertion vertex of ,

and where is an edge of with endpoints in . The node is called edgeintroduce node and the edge is the insertion edge of , or

for some and . The node is called forget node and is the forget vertex of .


if has exactly two children and , then , and . The node is called a join node.
The notion of a nice triple defined above is essentially the same as the one of nice tree decomposition in [10] (which in turn is an enhancement of the original one, introduced in [28]). As already argued in [10, 28], it is possible, given a tree decomposition to transform it in polynomial time to a new one of the same width and construct a collection such that the triple is nice.
Transfer triples and their fusion. Let be a triple where is a forest, , and , where . Keep in mind that contains all vertices and edges of except from the edges that are incident to vertices in . We call a transfer triple if, given a , if and only if and belong in different connected components of . The function will be used for indicating for each pair the “cost of transfering” from to in ( is not necessarily a distance function).
Let and be two transfer triples where , , and such that is a forest. Let also . We require a function that builds the transferring costs of moving in by taking into account the corresponding transferring costs in and . The values of are defined as follows:
Let . Let be the shortest path in containing and and let , ordered in the way these vertices appear in and assuming that . To simplify notation, we assume that is an edge of (otherwise, exchange the roles of and ). Given , we define (resp. ) as the edge incident to that appears before (resp. after) when traversing from to . We define the set of indices
Let , where numbers are ordered in increasing order and we also set . Then we set
Throughout the paper, we let , , and denote the number of vertices, the maximum degree, and the treewidth of the input graph, respectively. When we consider the (parameterized) decision version of the DiameterTree problem, we let also denote the desired cost of a solution.
3 ParaNPhardness results
We start with the parahardness result with parameter .
Theorem 1.
The DiameterTree problem is hard on outerplanar graphs with only one vertex of degree greater than 3, even with three different costs that satisfy the triangle inequality, and . Since outerplanar graphs have treewidth at most 2, in particular, DiameterTree is parahard parameterized by and .
Proof.
We present a simple reduction from 3Sat. Given a formula with variables and clauses, we create an instance of DiameterTree as follows. We may assume that there is no clause in that contains a literal and its negation. The graph contains a distinguished vertex and, for each clause , we add a clause gadget consisting of three vertices and five edges , , , , and . This completes the construction of . Note that does not depend on the formula except for the number of clause gadgets, and that it is an outerplanar graph with only one vertex of degree greater than 3; see Figure 1 for an illustration.
Let us now define the coloring and the cost function . For simplicity, we associate a distinct color with each edge of , and thus, with slight abuse of notation, it is enough to describe the cost function for every pair of incident edges of , as we consider symmetric cost functions. We will use just three different costs: 1, 5 and 10. We set
Note that this cost function satisfies the triangle inequality since the reload costs between edges incident to are 5 and 10, and the reload costs between edges incident to other vertices are 1.
We claim that is satisfiable if and only if contains a spanning tree with diameter at most . Since is a cut vertex and every clause gadget is a connected component of , in every spanning tree, the vertices of together with induce a tree with four vertices. Moreover the reload cost associated with a path from to a leaf of this tree is always at most . Therefore, the diameter of any spanning tree is at most plus the maximum reload cost incurred at by a path of .
Assume first that is satisfiable, fix a satisfying assignment of , and let us construct a spanning tree of with diameter at most . For each clause , the tree is the tree spanning and containing the edge between and an arbitrarily chosen literal of that is set to true by . is the union of all the trees constructed in this way. The reload cost incurred at by any path of traversing it is at most , since we never choose a literal and its negation. Therefore, it holds that .
Conversely, let be a spanning tree of with . Then, the reload cost incurred at by any path traversing it is at most since otherwise . For every , let be the subtree of induced by and let be one of the edges incident to in . We note that for any pair of clauses we have , since otherwise a path using these two edges would incur a cost of at . The variable in the literal is set by so that is true. All the other variables are set to an arbitrary value by . Note that is welldefined, since we never encounter a literal and its negation during the assignment process. It follows that is a satisfying assignment of . ∎
We proceed with the parahardness result with parameter .
Theorem 2.
The DiameterTree problem is hard on graphs with , even with two different costs, , and bounded number of colors. In particular, it is parahard parameterized by and .
Proof.
We present a reduction from the restriction of 3Sat to formulas where each variable occurs in at most three clauses; this problem was proved to be complete by Tovey [32]. It is worth mentioning that one needs to allow for clauses of size two or three, as if all clauses have size exactly three, then it turns out that all instances are satisfiable [32].
We may assume that each variable occurs at least once positively and at least once negatively, as otherwise we may set such variable to the value that satisfies all clauses in which it appears, and delete together with those clauses from the formula. We may also assume that each variable occurs exactly three times in the given formula . Indeed, let be a variable occurring exactly two times in the formula. We create a new variable and we add to two clauses and . Let be the new formula. Clearly and are equivalent, and both and occur three times in . Applying these operations exhaustively clearly results in an equivalent formula where each variable occurs exactly three times. Summarizing, we may assume the following property:

Each variable occurs exactly three times in the given formula of 3Sat. Moreover, each variable occurs at least once positively and at least once negatively in .
Given a formula with variables and clauses, we create an instance of DiameterTree with as follows. Let the variables in be . For every , we add to a variable gadget consisting of five vertices and five edges , and . For every , we add the edge . For every , the clause gadget in consists of a single vertex . We now proceed to explain how we connect the variable and the clause gadgets. For each variable , we connect vertex (resp. ) to one of the vertices corresponding to a clause of in which appears positively (resp. negatively). Finally, we connect vertex to the remaining clause in which appears (positively or negatively). Note that these connections are welldefined because of property . This completes the construction of , and note that it indeed holds that ; see Figure 2(a) for an example of the construction of for a specific satisfiable formula with and .
Let us now define the coloring and the cost function . We use nine colors associated with the edges of as follows. For , we set and , and all edges incident to or have color 3. Finally, for , we color the edges containing with colors in , so that incident edges get different colors, and edges corresponding to positive (resp. negative) occurrences get colors in (resp. ); note that such a coloring always exists as each clause contains at most three variables; see Figure 2(b). We will use only two costs, namely 0 and 1, and recall that we consider just symmetric cost functions. We set , for every , for every , and for every distinct . All other costs are set to 0.
We claim that is satisfiable if and only if contains a spanning tree with diameter . Assume first that is satisfiable, fix a satisfying assignment of , and let us construct a spanning tree of with diameter . For every , tree contains all the edges containing vertex or . If variable is set to true by , we include the edge to , and otherwise, that is, if is set to false by , we include the edge . Finally, for , we add to one of the edges containing that corresponds to a literal satisfying that clause. It can be easily checked that is a spanning tree of with diameter 0; see Figure 2(a) for an example.
Conversely, let be a spanning tree of with diameter . Since the cost associated with any two distinct colors in is 1, it follows that, for , vertex has degree one in . Therefore, the variable gadgets need to be connected in via the vertices , implying that all edges containing , for , belong to . For , in order for to contain all four vertices , by construction of and since all clause vertices have degree one in , tree necessarily contains exactly three out of the four edges of the 4cycle defined by . Since and , the missing edge is necessarily either or . We define an assignment of the variables as follows: for , if the edge belongs to , we set to true; otherwise, we set to false. We claim that satisfies . Indeed, let be a vertex in corresponding to an arbitrary clause of . Since has degree one in , it is attached to exactly one of the vertices for some . Suppose that the edge containing corresponds to a positive occurrence of , the other case being symmetric. Then, by construction, necessarily the edge containing is either or . In both cases, if the edge were in , this edge together with or would incur a cost of 1 in , contradicting the hypothesis that . Therefore, the edge cannot be in , implying that the edge must be in . According to the definition of the assignment , this implies that variable is set to true in , and therefore the clause corresponding to is satisfied by variable . This concludes the proof. ∎
Note that in the above reduction the cost function does not satisfy the triangle inequality at vertices or for , and recall that this is unavoidable since otherwise the problem would be polynomial [33]. It is worth mentioning that using the ideas in the proof of [22, Theorem 4 of the full version] it can be proved that the DiameterTree problem is also hard on planar graphs with , , and bounded number of colors; we omit the details here.
Finally, we present the parahardness result with parameter .
Theorem 3.
The DiameterTree problem is hard on planar graphs with and . In particular, it is parahard parameterized by and .
Proof.
We present a reduction from the Partition problem, which is a typical example of a weakly complete problem [19]. An instance of Partition is a multiset of positive integers, and the objective is to decide whether can be partitioned into two subsets and such that where .
Given an instance of Partition, we create an instance of DiameterTree as follows. The graph contains a vertex , called the root, and for every integer where , we add to six vertices and seven edges , , , , , , and . We denote by the subgraph induced by these six vertices and seven edges. We add the edges and, for , we add the edges and . Let be the graph constructed so far. We then define to be the graph obtained from two disjoint copies of by adding an edge between both roots. Note that is a planar graph with and . (The claimed bound on the treewidth can be easily seen by building a path decomposition of with consecutive bags of the form .)
Let us now define the coloring and the cost function . Again, for simplicity, we associate a distinct color with each edge of , and thus it is enough to describe the cost function for every pair of incident edges of . We define the costs for one of the copies of , and the same costs apply to the other copy. For every edge being either or , for , we set for each of the four edges incident with . For every edge , for , we set and . All costs associated with the two edges containing in one of the copies are set to . For , where and are the roots of the two copies of , we set for each of the four edges incident to . The cost associated with any other pair of edges of is equal to ; see Figure 3 for an illustration, where (some of) the reload costs are depicted in blue, and a typical solution spanning tree of is drawn with thicker edges.
We claim that the instance of Partition is a Yesinstance if and only if has a spanning tree with diameter at most .
Assume first that is a Yesinstance of Partition, and let be a solution. We define a spanning tree of with diameter as follows. We describe the subtree of restricted to one of the copies of , say . The spanning tree of is defined by union of two symmetric copies of , one in each copy of , together with the edge . Tree consists of the two edges and two paths (corresponding to the upper and the lower path, respectively defined as follows; see Figure 3). For , the path (resp. ) contains the edge (resp. ), and if we add the three edges to , and the edge to . Otherwise, if , we add the edge to and the three edges to . Since , it can be easily checked that both paths and have diameter in each of the two copies of , and therefore is a spanning tree of with diameter .
Conversely, let be a spanning tree of with . Let be the two copies of in , and let be their respective roots. Since the edge is a bridge of , it necessarily belongs to . By the construction of , the choice of the reload costs, and since , it can be verified that, for , consists of two paths intersecting at the root . Furthermore, (resp. ) contains the edge (resp. ) of the corresponding copy of , and the intersection of (resp. ) with the subgraph in the corresponding copy of is given by either the three edges (resp. ) or by the edge (resp. ). Therefore, for and , it holds that , where is the set of indices such that the edge belongs to path . Note also that, for , by construction we have that , implying in particular that . On the other hand, by the structure of it holds that
(1) 
Equation (1) implies, in particular, that . In other words, , thus the sets define a solution of Partition. This completes the proof. ∎
4 A polynomialtime algorithm on cactus graphs
In this section we present a polynomialtime algorithm to solve the DiameterTree problem on cactus graphs, equivalently called cacti. We first need some definitions.
A biconnected component, or block, of a graph is a maximal biconnected induced subgraph of it. The block tree of a graph is a tree whose nodes are the cut vertices and the blocks of . Every cut vertex is adjacent in to all the blocks that contain it. Two blocks share at most one vertex. The block tree of a graph is unique and can be computed in polynomial time [12]. A graph is a cactus graph if every block of it is either a cycle or a single edge. We term these blocks as cycle block and edge block, respectively. It is wellknown that cacti have treewidth at most 2. Given a forest and two vertices and , we define to be if and are in the same tree of and where is the given reload cost function, and otherwise. Given a tree and a vertex , we define the eccentricity of in to be .
We present a polynomialtime algorithm that solves the decision version of the problem, which we call DiameterTree*: the input is an edgecolored graph and an integer , and the objective is to decide whether the input graph has a spanning tree with reload cost diameter at most . The algorithm to solve DiameterTree* uses dynamic programming on the block tree of the input graph.
As we aim at a truly polynomialtime algorithm to solve DiameterTree, we cannot afford to solve the decision version for all values of . To overcome this problem, we perform a double binary search on the possible solution values and two appropriate eccentricities, resulting (skipping many technical details) in an extra factor of in the running time of the algorithm, where is the diameter of a minimum cost spanning tree. This yields a polynomialtime algorithm solving DiameterTree in cactus graphs.
Roughly speaking, the algorithm first fixes an arbitrary noncut vertex of and the block that contains it. Then it processes the block tree of in a bottomup manner starting from its leaves, proceeding towards while maintaining partial solutions for each block. At each step of the processing, it uses an algorithm that solves an instance of the 2Sat problem as a subroutine. The intuition behind the instances of 2Sat created by the algorithm is the following.
Suppose that we are dealing with a cycle block of the block tree of (the case of an edge block being easier). Note that any spanning tree of contains all edges of except one. Let be the graph processed so far (including ). For each potential partial solution in , we associate, with each edge of , a variable that indicates that is the nonpicked edge by the solution in . Now, for any two such variables corresponding to intersecting blocks, we add to the formula of 2Sat essentially two types of clauses: the first set of clauses, namely , guarantees that the nonpicked edges (corresponding to the variables set to true in the eventual assignment) indeed define a spanning tree of , while the second one, namely , forces this solution to have diameter and eccentricity not exceeding the given budget . The fact the is a cactus allows to prove that these constraints containing only two variables are enough to compute an optimal solution in .
Theorem 4.
The DiameterTree problem can be solved in polynomial time on cacti.
Proof.
We start with a few more definitions needed in the algorithm. Given a graph , we denote by the set of spanning trees of , and by the set of blocks of . We omit from the notation if no ambiguity arises. We assume without loss of generality that is connected. For a block , we denote by the set of blocks that are immediate descendants of in the block tree. With a slight abuse (since we ignore the cut vertices in the block tree), we will refer to them as the children of . The parent of a block is the first block after on the path from to in the block tree. We denote by the subgraph of induced by the union of all descendants (including itself). The anchor of a block is the cut vertex separating from its parent if , and if .
Let be a cycle block, , and assume, without loss of generality, that . Clearly, the graph is connected. Moreover, is a cut vertex of unless . For we define as the set of vertices that are reachable from in without traversing . See Figure 4 for an illustration. We denote the subgraph of induced by , as . Note that and are in and if then . Since the degree of in is at most two, a spanning tree of is a union of two spanning trees, a tree spanning and a tree spanning . Moreover, and intersect only at .
We proceed with the description of the algorithm. At every block , we compute a function of partial solutions. If is an edge block consisting of the edge , then is:

a spanning tree of ,

of diameter at most

that minimizes the eccentricity of ,
if such a tree exists, and otherwise.
If