### Bounded Signal Flow Over Vertices

In this subsection, we investigate how the vertex-wise structure of the source–target pairs influences the computational complexity of MAXIMUM TREE ORIENTATION. More specifically, first we consider the parameter *m*_{
v
} denoting the maximum number of source–target paths passing through a vertex. We show that MTO can be solved in *O*(2 ^{mv} ⋅ |*P*| + *n*^{4}) time. In other words, MTO is fixed-parameter tractable with respect to the parameter *m*_{
v
} . Motivated by this positive result, we explore in more depth the structure of the source–target paths that pass through a vertex. To this end, we introduce the concept of "cross pairs" and show that for cross-pair-free instances MTO can be solved in *O*(*n*^{2}) time. Informally speaking, an instance is cross-pair-free if the input tree can be rooted such that for each source–target pair one endpoint is an ancestor of the other one. Then, for a rooted MTO instance a cross pair is a source–target pair such that none of its endpoints is the ancestor of the other endpoint. By refining the solving strategy for cross-pair-free instances, we show that MAXIMUM TREE ORIENTATION can be solved in O\left({\mathsf{\text{2}}}^{{q}_{v}}\cdot {n}^{2}\cdot {q}_{v}\right) time, where *q*_{
v
} denotes the maximum number of cross pairs passing through a vertex.

All algorithms in this subsection are based on dynamic programming, and, hence, since source–target pair weights can easily be incorporated, extend to W-MTO.

#### Parameter "Maximum Number of Pairs Per Vertex"

Here, we show that W-MTO is fixed-parameter tractable for the parameter *m*_{
v
} denoting the maximum number of source–target pairs passing through a vertex. To this end, we prove in Theorem 1 that we can construct in polynomial time a tree decomposition of the conflict graph of treewidth at most *m*_{
v
} . Recall that (weighted) MTO is equivalent to (weighted) VERTEX COVER on the conflict graph (see Proposition 1). Thus, the running time follows by the fact that (weighted) VERTEX COVER can be solved in *O*(2^{tw}*n*) time, given a tree decomposition of width tw [15]. □

**Theorem 1.** *On n-vertex trees*, WEIGHTED MAXIMUM TREE ORIENTATION *is solvable in O*(2 ^{m}*v*⋅ |*P*| + *n*^{4}) *time, where m*_{
v
} *denotes the maximum number of source–target pairs passing through a vertex*.

*Proof*. First, we show how to construct a tree decomposition of width *m*_{
v
} of the conflict graph in polynomial time. Let (*T* = (*V*, *E*), *P*) denote an MTO instance and let *G*_{
c
} = (*P*, *E*_{
c
} ) denote the associated conflict graph. The basic idea is that we can use *T* as the underlying tree of a tree decomposition of *G*_{
c
} = (*P*, *E*_{
c
} ). More specifically, the tree decomposition is given by 〈{*P*_{
v
} | *v* ∈ *V*}, *T*〉 for all *v* ∈ *V*. Recall that *P*_{
v
} denotes the set of source–target pairs passing through *v*. Observe that each vertex *p* ∈ *P* of the conflict graph appears exactly in the bags *X*_{
v
} for all *v* ∈ *V* (path_{
T
}(*p*)). Moreover, note that if two source–target pairs *p* = [*s*, *t*] and *p*' = [*s*', *t*'] are in conflict (and hence are adjacent in the conflict graph), then path_{
T
}(*s*, *t*) and path_{
T
}(*s*', *t*') have at least one edge and thus at least two vertices in common. Hence, every edge of the conflict graph is contained in at least one of the *X*_{
v
} 's. Thus, all conditions of a tree decomposition are fulfilled. Moreover, the width of this tree decomposition is clearly *m*_{
v
} - 1. The conflict graph, the sets *P*_{
v
} , and the tree decomposition can be computed in *O*(*n*^{4}) time. Thus, the overall running time follows by the fact that WEIGHTED VERTEX COVER can be solved in *O*(2^{tw} |*P*|) time, given a tree decomposition of width tw of *G*_{
c
}[15].

#### Cross Pairs

In Theorem 1, we have shown that W-MTO is fixed-parameter tractable with respect to the parameter *m*_{
v
} . In the following, we will strengthen this result by showing that W-MTO is fixed-parameter tractable with respect to the parameter "number of a special type of source–target pairs (the so-called cross pairs) passing through a vertex". The idea is to identify a "trivial" (that is, polynomial-time solvable) special case of the problem and then to investigate instances that are close to these trivial instances, their closeness measured in terms of a certain parameter which is referred to as *distance from triviality*[19, 20].

In the following, we will always consider *rooted* trees. Informally speaking, a cross-pair-free instance only contains source–target pairs whose corresponding paths are directed either towards the root or towards the leaves, but do not change their direction. Cross-pair-free instances of W-MTO are of special interest since they constitute our "trivial instances".

**Definition 1**. *Let* (*T* = (*V*, *E*), *P*, *ω*) *be an instance of W-MTO where T is a rooted tree. A source–target pair p* = [*a*, *b*] ∈ *P is called cross pair if neither a is an ancestor of b nor b an ancestor of a. An instance of W-MTO is called cross-pair-free if T can be rooted such that P does not contain any cross pairs*.

#### Cross-pair-free Instances

Now, we devise a dynamic-programming-based algorithm solving W-MTO in quadratic time on cross-pair-free instances.

**Theorem 2**. *On n-vertex trees*, WEIGHTED MAXIMUM TREE ORIENTATION *for cross-pair-free instances with given root can be solved in O*(*n*^{2}) *time*.

*Proof*. **Algorithm**. We present a dynamic programming algorithm with quadratic running time solving a cross-pair-free W-MTO instance (*T* = (*V*, *E*), *P*, *ω*) with root *r*. For the presentation of the algorithm, we use the following notation. For *v* ∈ *V*, let *T*_{
v
} be the subtree of *T* rooted at *v*. For all *v*, *w* ∈ *V* with *v* ≺ *w* (that is, *v* is an ancestor of *w*) let {T}_{w}^{v} denote the subtree of *T* induced by {V}_{w}^{v}:=V\left({T}_{w}\right)\cup V\left(\mathsf{\text{pat}}{\mathsf{\text{h}}}_{T}\left(v,w\right)\right).

For ease of presentation, let {V}_{w}^{w}:=V\left({T}_{w}\right). Moreover, let {P}_{w}^{v}:=\left\{\left[s,t\right]\in P|s,t\in {V}_{w}^{v}\right\}. That is, {T}_{w}^{v} is the tree consisting of the path path_{
T
}(*v*, *w*) and the subtree *T*_{
w
} rooted at *w*, and {P}_{w}^{v} are the pairs with both endpoints in {T}_{w}^{v}. Finally, the *weight* of an orientation {\overrightarrow{T}}_{w}^{v} of \left({T}_{w}^{v},{P}_{w}^{v}\right) is the sum of the weights of the pairs in {P}_{w}^{v} satisfied by {\overrightarrow{T}}_{w}^{v}.

The algorithm maintains an *n* × *n* dynamic programming table *S*, containing for each *v*, *w* ∈ *V* with *v* ≺ *w* or *v* = *w* the two entries *S*(*v*, *w*) and *S*(*w*, *v*). The goal of the dynamic programming procedure is to fill *S* in accordance with the following definition.

For all *v*, *w* ∈ *V* with *v* ≺ *w*, entry *S*(*v*, *w*) is the maximum weight of an orientation of \left({T}_{w}^{v},{P}_{w}^{v}\right) among all orientations of \left({T}_{w}^{v},{P}_{w}^{v}\right) orienting the path between *v* and *w* from *v* to *w* (that is, away from the root). Analogously, *S*(*w*, *v*) is the maximum weight of an orientation of \left({T}_{w}^{v},{P}_{w}^{v}\right) among all orientations of \left({T}_{w}^{v},{P}_{w}^{v}\right) orienting the path between *v* and *w* from *w* to *v* (that is, towards the root). Note that in the case *v* = *w* we have that *S*(*v*, *v*) is the weight of an optimal orientation of the subtree rooted at *v*.

Next, we describe how our algorithm computes the entries of *S* in accordance with this definition. The weight of an optimal orientation of (*T*, *P*) can then be found in *S*(*r*, *r*).

To compute the entries of *S*, visit all vertices *w* ∈ *V* in a bottom-up traversal. Then, for each *w* consider all vertices *v* ∈ *V* with *v* = *w* or *v* ≺ *w* and set (omit the sum if *w* is a leaf):

\begin{array}{c}S\left(v,w\right):=A\left(v,w\right)\\ \phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}+\sum _{u\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{is}}\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{a}}\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{child}}\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{of}}\phantom{\rule{2.77695pt}{0ex}}w}\mathsf{\text{max}}\left\{S\left(u,w\right),S\left(v,u\right)-A\left(v,w\right)\right\},\end{array}

(1)

\begin{array}{c}S\left(w,v\right):=A\left(w,v\right)\\ \phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}\phantom{\rule{1em}{0ex}}+\sum _{u\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{is}}\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{a}}\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{child}}\phantom{\rule{2.77695pt}{0ex}}\mathsf{\text{of}}\phantom{\rule{2.77695pt}{0ex}}w}\mathsf{\text{max}}\left\{S\left(w,u\right),S\left(u,v\right)-A\left(w,v\right)\right\}.\end{array}

(2)

Herein, *A*(*v*, *w*) denotes the sum of the weights of the source–target pairs with both endpoints on path_{
T
}(*v*, *w*) that are satisfied when orienting the path between *v* and *w* from *v* to *w*, that is,

\begin{array}{l}A(v,w):=\omega (\{[s,t]\in P|\\ s,t\in V({\text{path}}_{T}(v,w))^s\prec t\})\mathrm{.}\end{array}

(3)

Analogously, *A*(*v*, *w*):= *ω* ({[*s*, *t* ∈ *P* | *s*, *t* ∈ *V* (path_{
T
}(*v*, *w*)) ∧ *t* ≺ *s*}). Moreover, for ease of presentation we assume that *A*(*v*, *v*) = 0.

**Correctness**. For the correctness of the algorithm note the following. For a leaf *w* and an ancestor *v* of *w*, the tree {T}_{w}^{v} is identical to the path path_{
T
}(*v*, *w*). Hence, the sum of the weights of pairs that can be satisfied by orienting the path either from *v* to *w* or from *w* to *v* is *A*(*v*, *w*) and *A*(*w*, *v*), respectively. Next, consider the case that *w* is an inner vertex and let *v* be an ancestor of *w*. Moreover, let *u*_{1},…, *u*_{
ℓ
} denote the children of *w*. We argue that the maximum weight of an orientation of \left({T}_{w}^{v},{P}_{w}^{v}\right) orienting the edges on path_{
T
}(*v*, *w*) towards *w* equals

A\left(v,w\right)+\sum _{i=1}^{\ell}\mathsf{\text{max}}\left\{S\left({u}_{i},w\right),S\left(v,{u}_{i}\right)-A\left(v,w\right)\right\},

(4)

and, hence, *S*(*v*, *w*) is computed correctly. To this end, consider a maximum-weight orientation {\overrightarrow{T}}_{w}^{v} of \left({T}_{w}^{v},{P}_{w}^{v}\right) orienting the edges on path_{
T
}(*v*, *w*) towards *w*. If, for a child *u*_{
i
} , {\overrightarrow{T}}_{w}^{v} contains the arc (*u*_{
i
} , *w*), then the contribution of the source–target pairs in {P}_{w}^{v} with at least one endpoint in {T}_{{u}_{i}} to the weight of {\overrightarrow{T}}_{w}^{v} is *S*(*u*_{
i
} , *w*); note that no source–target pair of {P}_{w}^{v} with exactly one endpoint in {T}_{{u}_{i}}^{w} is satisfied by {\overrightarrow{T}}_{w}^{v}, and thus the contribution of these pairs is *S* (*u*_{
i
} , *w*) (a smaller contribution would contradict the optimality of {\overrightarrow{T}}_{w}^{v}). Moreover, if for a child *u*_{
i
} the oriented tree {\overrightarrow{T}}_{w}^{v} contains the arc (*w*, *u*_{
i
} ), then it follows by a similar argument that the contribution of the paths in {P}_{w}^{v} with at least one endpoint in V\left({T}_{{u}_{i}}\right) is *S*(*v*, *u*_{
i
} ) - *A*(*v*, *w*). The only difference is that the contribution of the source–target pairs with both endpoints in *V* (path_{
T
}(*v*, *w*)) is already considered in the above formula, and, hence, must be subtracted from *S*(*v*, *u*_{
i
} ).

**Running time**. For the running time bound, we show that *A* can be computed in *O*(*n*^{2}) time in a preprocessing step. Then, the overall running time is clearly bounded by

O\left({\displaystyle \sum _{v\in V}}{\displaystyle \sum _{w\in V}}{{\displaystyle \text{deg}}}_{T}(w)\right)=O\left({\displaystyle \sum _{v\in V}}n\right)=O({n}^{2})\mathrm{,}

(5)

since ∑ _{
w∈V
} deg_{
T
}(*w*) = 2(*n* - 1) in trees. Clearly for *v*, *w* ∈ *V* with *v* ≺ *w* the matrix entries *A*(*v*, *w*) and *A*(*w*, *v*) can be computed by setting

A\left(v,w\right):=\omega \left(\left[v,w\right]\right)+A\left(v,y\right)+A\left(x,w\right)-A\left(x,y\right)

(6)

and

A\left(w,v\right):=\omega \left(\left[w,v\right]\right)+A\left(w,x\right)+A\left(y,v\right)-A\left(y,x\right),

(7)

where *x* is the neighbor of *v* and *y* is the neighbor of *w* on path_{
T
}(*v*, *w*). This assumes, however, that all the entries of *A* for pairs with distance *l* - 1 are known before computing the entries of the pairs with distance *l*. This can be ensured by using a queue (first-in-first-out data structure) as follows. For the computation of *A*, first, for all edges {*v*, *w*} ∈ *E* with *v* ≺ *w* set *A*(*v*, *w*):= *ω*([*v*, *w*]) and *A*(*w*, *v*):= *ω*([*w*, *v*]) (let *ω*([*s*, *t*]):= 0 if [*s*, *t*] ∉ *P*) and append the pair (*v*, *w*) at the tail of the queue. After each edge has been processed, proceed as follows. Until the queue is empty, let (*x*, *w*) denote the next element at the head of the queue and let *v* denote the parent of *x* and let *y* denote the parent of *w* in *T* (if *x* = *r* remove (*x*, *w*) from the head position of the queue and do nothing else). It is easy to verify that the entries for the pairs (*x*, *w*) and (*v*, *y*) have already been computed and, hence, can be used to compute *A*(*v*, *w*) and A(*w*, *v*) as described above. Finally, we remove (*x*, *w*) from the head position of the queue and append (*v*, *w*) at the tail of the queue. Clearly, for every pair *v*, *w* of vertices with *v* ≺ *w*, we need a constant number of operations to compute the two table entries *A*(*v*, *w*) and *A*(*w*, *v*), resulting in an overall running time bound of *O*(*n*^{2}). □

Note that if the root of a cross-pair-free W-MTO instance is not known, it can be calculated in *O*(*n*|*P*|) time by trying all roots and then checking for each pair if the least common ancestor is one of the two endpoints.

As an immediate consequence of Theorem 2, we can improve the cubic-time algorithm for MTO on paths by Medvedovsky et al. [3] to quadratic time. Herein, we use that every path rooted at one of its endpoints results in a cross-pair-free instance of MTO.