A duality based 2-approximation algorithm for maximum agreement forest

We give a 2-approximation algorithm for the Maximum Agreement Forest problem on two rooted binary trees. This NP-hard problem has been studied extensively in the past two decades, since it can be used to compute the rooted Subtree Prune-and-Regraft (rSPR) distance between two phylogenetic trees. Our algorithm is combinatorial and its running time is quadratic in the input size. To prove the approximation guarantee, we construct a feasible dual solution for a novel exponential-size linear programming formulation. In addition, we show this linear program has a smaller integrality gap than previously known formulations, and we give an equivalent compact formulation, showing that it can be solved in polynomial time.


Introduction
Evolutionary relationships are often modeled by a rooted tree, where the leaves represent a set of species, and internal nodes are (putative) common ancestors of the leaves below the internal node.Such phylogenetic trees date back to Darwin [10], who used them in his notebook to elucidate his thoughts on evolution.For an introduction to phylogenetic trees we refer to [11,22] The topology of phylogenetic trees can be based on different sources of data, e.g., morphological data, behavioral data, genetic data, etc., which can lead to different phylogenetic trees on the same set of species.
Such partly incompatible trees may actually be unavoidable: there exist non-tree-like evolutionary processes that preclude the existence of a phylogenetic tree, so-called reticulation events, such as hybridization, recombination and horizontal gene transfer [16,17].Irrespective of the cause of the conflict, the natural question arises to quantify the dissimilarity between such trees.Especially in the context of reticulation, a particularly meaningful measure of comparing phylogenetic trees is the Subtree Prune-and-Regraft distance for rooted trees (rSPR-distance), which provides a lower bound on a certain type of these non-tree evolutionary events.The problem of finding the exact value of this measure for a set of species motivated the formulation of the Maximum Agreement Forest Problem (MAF) by Hein, Jian, Wang and Zhang [15].
In the definition of MAF by Hein et al. we are given two rooted binary trees, each having its leaves labeled with the same set of labels L, where in each tree each leaf has one label and each label is assigned to one leaf.The problem is to find a minimum set of edges to be deleted from the two trees, so that the rooted trees in the resulting two forests (where the choice of the root is the natural choice) can be paired up into pairs of isomorphic trees.Two rooted trees are isomorphic if their restrictions are the same, where the restriction of a tree is obtained by considering the minimal tree spanning the same set of leaves from L, and then contracting nodes with only a single child.
Since the introduction by Hein et al. in [15], in which they also proved NP-hardness, MAF has been extensively studied, mostly in its version of two rooted binary input trees.After Allen and Steel [1] pointed out that the claim by Hein et al. that solving MAF on two rooted directed trees computes the rSPR-distance between the trees is incorrect, Bordewich and Semple [5] presented a subtle redefinition of MAF, whose optimal value does coincide with the rSPR-distance.In this redefinition it is required that the two forests agree on the tree containing the original roots of the input trees.This has now become the standard definition of MAF, for which Bordewich and Semple [5] showed that NP-hardness still holds, and Rodrigues [19] showed that it is in fact APX-hard.
The problem has attracted a lot of attention, and indeed has become a canonical problem in the field of phylogenetic networks.Many variants of MAF have been studied, including versions where the input consists of more than two trees [6,7], and where the input trees are unrooted [27,26] or non-binary [20,25].We will concentrate on MAF in its classical form with two rooted binary input trees, and we will be concerned with the worst-case approximability of the problem.The literature includes many other approaches to the problem, including fixed-parameter tractable algorithms (e.g., [27,26]) and integer linear programming [28,29].But the quest for better approximation algorithms has become central within the MAF literature.
Our result improves over a sequence spanning 10 years of approximation algorithms, starting with the first correct 5-approximation [3].This was followed by several 3-approximations [4,20,26], each one improving on the running time, and the last one giving a relatively simple and elegant proof.A 2.5-approximation followed [23].In 2016, Chen et al. [9] described a 7/3-approximation.Independently in the same year, a subset of the present authors [21] gave a factor 2 approximation algorithm.Subsequently, Chen et al. [8] gave a different factor 2 approximation algorithm using very different methods, and with a cubic running time.
The 2-approximation algorithm presented in the current paper may be viewed as the full version of the algorithm in [21].However, while the algorithm presented here is similar in spirit, it differs in many details, and the exposition is entirely new.Although the algorithm and analysis remain quite subtle, this version is significantly shorter and clearer.Moreover, we show how our algorithm can, with some care, be implemented in quadratic time ( [21] discuss only a polynomial time bound).This improves over the cubic running time of Chen et al. [8].
Our 2-approximation algorithm differs from previous works in two key aspects.First of all, our algorithm takes a global approach; choices may depend on large parts of the instance.All the previous algorithms that obtained a worse approximation ratio considered only local, constant-sized, substructures.Secondly, we introduce a novel integer linear programming formulation for the analysis.Our approximation guarantee is proved by constructing a feasible solution to the dual of this linear program, rather than arguing locally about the objective of the optimal solution.
While we provide a new integer linear programming formulation and exploit its linear relaxation in our analysis, we do not need to actually solve the relaxation as part of our algorithm.In fact, the formulation has an exponential number of variables, and so it is not immediately clear that it can be efficiently optimized.We show that it can be reformulated as a compact LP, with only a polynomial number of variables and constraints.We believe that this is interesting for a number of reasons.It implies that the linear relaxation can be solved efficiently (in polynomial time); this may be of future utility in obtaining better approximation guarantees using LP-rounding techniques, which do require an optimal solution to the relaxation.Moreover, the compact formulation is amenable to use in commercial integer programming solvers.There is a previous formulation due to Wu [28], but our formulation is significantly stronger: the integrality gap of the relaxation of Wu is at least 3.2, whereas for ours we show it is at most 2, and in fact the worst example that we are aware of has integrality gap 1.25 (see the appendix).Finally, we remark that our compact formulation can be easily adapted to handle other variants of MAF-for example, settings with more than two trees.
We have implemented and tested our algorithm, as well as the compact formulation [18].The implementation has been designed so that it is easy to step through the algorithm and explore its behaviour on a given instance; the reader may find it helpful when examining the technical details of the algorithm.
Outline.We define the problem and introduce necessary notation in Section 2. Section 3 describes the algorithm, and proves that it produces a feasible solution to MAF.In Section 4, we introduce the linear program, and describe a feasible solution to its dual that can be maintained by the algorithm.We then show the objective value of this dual solution is always at least half the objective value of the MAF solution, which proves the approximation ratio of two.In Section 5, we show a compact formulation of the (exponential sized) linear program used for the analysis.In the appendices, we show that our algorithm can be implemented to run in time quadratic in the size of the input, and we give an example that shows that a previously known integer linear program [28] is not as strong as the formulation introduced here.

Preliminaries
The input to the Maximum Agreement Forest problem (MAF) consists of two rooted binary trees T 1 and T 2 , where the leaves in each binary tree are labeled with the same label set L. Each leaf has exactly one label, and each label in L is assigned to exactly one leaf in T 1 , and one leaf in T 2 .We will use L also to denote the leaves of the trees.
Let V 1 and V 2 denote the node set of T 1 and T 2 respectively, and let We call all nodes in V \ L internal nodes.We let L(u) denote the set of leaves that are descendants of a node u ∈ V .
We will use the following notational conventions: we use u and v to denote arbitrary nodes (including leaves), if the node we refer to is an internal node in V 2 , we will use û and v, and we use the letters x, y and w to refer to leaves.
For A ⊂ L we use V i [A] to denote the set of (internal) nodes in T i that lie on a path between any two leaves in A for i ∈ {1, 2}, and define Definition 1.We will say that a set We say a partition P of L overlaps in U ⊆ V if there exist A, A ∈ P, A = A such that A and A overlap in U .
For A ⊆ L, we let lca i (A) denote the least common ancestor of A in T i .We will sometimes omit braces of explicit sets and write, e.g., lca 1 (x 1 , x 2 , x 3 ) instead of lca 1 ({x 1 , x 2 , x 3 }).
For nodes u, v in the same tree, we use u We call a triple of leaves incompatible if it is not a compatible set.Note that L ⊆ L is compatible precisely if the subtrees induced by L in T 1 and T 2 are isomorphic.
A feasible solution to MAF is a partition P = {A 1 , A 2 , . . ., A k } of L such that every component A i is compatible, and A i does not overlap A j , for each i = j.The cost of this solution is defined to be |P| − 1.This cost corresponds to the number of edges that must be deleted from T 1 , as well as the same number from T 2 , so that in both of the resulting forests, each A i ∈ P is the leaf set of a single tree.
In order for MAF to correspond to the rSPR distance, it is necessary to add an additional node ρ to L, as a unique sibling to the root in both T 1 and T 2 .This is the distinction between the original definition of MAF by Hein [15] and the correction by Bordewich and Semple [5].We simply assume that this addition is already included in the input instance, after which there is no need to distinguish this additional leaf from the others.
To describe our algorithm, it will be convenient to extend the notion of compatibility.

The Red-Blue Algorithm
The algorithm maintains a partition P of L, which at the end of the algorithm will correspond to a feasible solution to MAF.The algorithm will maintain the invariant that P does not overlap in V 2 .Observe that this is equivalent to defining P to be the leaf sets of the trees in a forest, obtained by deleting edges from T 2 .
The algorithm works towards feasibility by iteratively refining P, focusing each iteration on a set of leaves L(u) for some u ∈ V 1 , for which the current partition is infeasible in some (quite narrowly defined) way.At the end of the iteration the solution is feasible if we restrict our attention to L(u), and even if we consider L(u) ∪ {w} for any arbitrary w ∈ L \ L(u).
We use the following definition to specify which sets L(u) the algorithm considers.
Definition 4. Given an infeasible partition P that does not overlap in V 2 , we call u ∈ V 1 a root-of-infeasibility if at least one of the following holds: (a) P is not L(u)-compatible; (c) there exists a component A in P such that A \ L(u) = ∅, and A ∩ L(u) ∪ {w} is not compatible for all w ∈ A \ L(u).
Observe that if u ∈ V 1 is a root-of-infeasibility, then any ancestor of u is a root-of-infeasibility.We will say an internal node u in tree T i is the "lowest" node with property Γ if property Γ does not hold for any of u's descendants in T i .The algorithm will identify a lowest node u ∈ V 1 that is a root-of-infeasibility.
Given a root-of-infeasibility u ∈ T 1 , we partition L into R, B, W , where R = L(u r ) and B = L(u ) for the two children u and u r of u.We will refer to this partition as a coloring of the leaves; we will refer to the leaves in R as red leaves, the leaves in B as blue leaves and the leaves in W as white leaves.We call a component of P tricolored if it has a nonempty intersection with R, B and W , and bicolored if it has a nonempty intersection with exactly two of the sets R, B, W .A component is called multicolored if it is either tricolored or bicolored, and unicolored otherwise.
Observation 1.Let u be a lowest root-of-infeasibility for P, and consider the coloring R, B, W , where R = L(u r ) and B = L(u ) for the two children u and u r of u.Then the set of multicolored components of P consists of either at most two bicolored components or exactly one tricolored component.
, and so at most one component of P covers lca 1 (R), and at most one covers lca 1 (B).The observation thus follows immediately, since any bicolored component covers either lca 1 (R) or lca 1 (B), and any tricolored component covers both lca 1 (R) and lca 1 (B).
We note that the above observation can be refined; it is possible to show that P contains either one tricolored component or exactly two bicolored components; see Lemma 12 in Section 4.3.
In Figure 1, we give an example of an input T 1 , T 2 and a coloring of the leaves, where R 1 can be a single leaf in R, or it can be a tree with leaves labeled by a compatible subset R 1 ⊂ R with likewise interpretations for the other capital leaves in this and future figures; the caption gives three partitions such that u satisfies exactly one of the three conditions of Definition 4: If P = {L}, u satisfies (a).Note that u is indeed a lowest root-of-infeasibility, since {R 1 , R 2 , W 3 } and {B 1 , B 2 , W 3 } are compatible sets, so u and u r do not satisfy (c) (nor (a) and (b)).
. Again, u is a lowest root-of-infeasibility(clearly u and u r does not satisfy (a) and (b); they also do not satisfy (c) since Observe that in this case u is again a lowest root-of-infeasibility.Make-R ∪ B-compatible(P, (R, B, W )).
An overview of the algorithm is given above.The procedures will be described in detail in the subsequent subsections, along with with lemmas regarding the properties they ensure.
We will refer to a pass through the main while-loop of the algorithm as an "iteration".In order to simplify the statement of the lemmas, we will make statements like "let P be the partition after ProcedureName(P, (R, B, W ))".This implicitly assumes that (R, B, W ) was a coloring chosen in the beginning of the current iteration of the Red-Blue algorithm (and thus, that lca 1 (R ∪ B) was a lowest root-ofinfeasibility at that moment), and that P is the partition resulting from calling ProcedureName(P, (R, B, W )) in the current iteration.
Finally, the in front of certain lines will be used to refer to these lines in the analysis in Section 4.2.
Figure 2: Illustration of Make-R ∪ B-compatible(P, (R, B, W )). Because P and P do not overlap in V 2 , we can represent these as the leaf sets of trees in a forest obtained by deleting edges from T 2 .In this figure and the following figures the dashed edges represent deleted edges.

Make-R ∪ B-compatible
procedure Make-R ∪ B-compatible(P, (R, B, W )) while ∃A ∈ P that is not R ∪ B-compatible do Let û be a lowest internal node in V 2 [A] for which A ∩ L(û) intersects both R and B.
P ← P \ {A} ∪ {A ∩ L(û), A \ L(û)}.end while end procedure An example is given in Figure 2. We note that in general, the choice of û does not have to be unique, and that multiple refinements may be needed to make the partition R ∪ B-compatible.
As observed above, for any partition P that does not overlap in V 2 , there is a set of edges in T 2 , such that P consists of the leaf sets of the trees in the forest obtained after deleting these edges.Our refinement is equivalent to deleting the edge from û towards the root in T 2 and hence the resulting partition does not overlap in V 2 if the original partition did not overlap in T 2 .
Lemma 1.Let P be the partition after Make-R ∪ B-compatible(P, (R, B, W )). Then P is a refinement of P that does not overlap in V 2 and is R ∪ B-compatible.
Proof.First, observe P is R-compatible and B-compatible, since u's children are not roots-of-infeasibility.If P is R ∪ B-compatible then P is not modified by the procedure, and the lemma is vacuously true.Otherwise, the procedure refines P, and we already mentioned above that the resulting partition P does not overlap in V 2 provided that P does not overlap in V 2 .The procedure ends when there are no sets in P that are not R ∪ B-compatible, so the only thing left to show is that this procedure halts.Because û was chosen to be the lowest internal node in V 2 [A] such that A ∩ L(û) intersects both R and B, the children of û, say ûr and û , are so that A ∩ L(û r ) and A ∩ L(û ) can only intersect one of R and B. Therefore A ∩ L(û) is R ∪ B-compatible, where A was not, and thus the number of R ∪ B-compatible components in P increases, which can only happen at most |L| times.
Observe that if P is R ∪ B-compatible, then any refinement of P is also R ∪ B-compatible, hence we may assume that the partition at any later point in the current iteration of the Red-Blue Algorithm is R ∪ B-compatible.

Make-Splittable
The goal of the next two procedures is to further refine the partition so that there is no overlap in We will do this in two steps, the first of which will achieve the following property.
procedure Make-Splittable(P, (R, B, W )) while ∃A ∈ P that is not splittable do Let û be a lowest internal node in V 2 [A] such that A∩L(û) is bicolored and A\L(û) intersects precisely the same colors as A.
First, note that by the same arguments as in the previous subsection, the partition that results from Make-Splittable does not overlap in V 2 if the original partition did not overlap in V 2 .It is easy to see that if A is bicolored and not splittable, then there exists û ∈ We prove below in Lemma 2 that if A is tricolored, we can additionally ensure that A \ L(û) is tricolored.For this to hold, we need that P is R ∪ B-compatible, which by Lemma 1 is indeed true when Make-Splittable is called.
As a first example of Make-Splittable, consider }} that was the output of Make-R ∪ B-compatible depicted in Figure 2. In this example P is already splittable.In Figure 3 a more interesting example is given.Lemma 2. Make-splittable is well-defined, in that a node û satisfying the desired properties in line can always be found.

Proof. As noted above the existence of û is clear when
Lemma 3. Let P be the partition after Make-splittable(P, (R, B, W )). Then P is a refinement of P that does not overlap in V 2 and in which every component is splittable.
Proof.By Lemma 2, and since each iteration increases the number of components in P, Make-splittable must terminate, and by its definition, the final partition P contains only splittable components.Clearly P is a refinement of P; it does not overlap in V 2 by the same arguments as used in the proof of Lemma 1.
Before continuing, we summarize the properties of the partition that is the result after Make-Splittable that will be useful in the proof of the approximation guarantee in Section 4. To describe these, we need the notion of a top component.Definition 6.Given the partition P at the start of the current iteration, and P another partition encountered in the current iteration, let D be the components that were created during the current iteration, i.e., D = P \P.Then A ∈ D is a top component if there exists no A ∈ D such that lca 2 (A) ≺ lca 2 (A ).
Lemma 4. Let P (0) denote the partition at the start of a given iteration, and (R, B, W ) the coloring of the leaves that is selected, let P (1) denote the partition after Make-R ∪ B-compatible(P (0) , (R, B, W )), and let P (2) denote the partition after Make-Splittable(P (1) , (R, B, W )), 1.Only multicolored components are subdivided by the iteration, i.e., if A ∈ P (0) \ P (2) , then A is multicolored.
3. The number of tricolored components in P (2) is the same as in P (1) .
4. Any tricolored component in P (1) or P (2) that is not a top component contains no compatible tricolored triple.
5. Any bicolored component A in P (2) that is not a top component satisfies that lca 2 (A) is not overlapped by A ∩ C for any color C ∈ {R, B, W }. In other words, L(û ) ∩ A and L(û r ) ∩ A are unicolored where û and ûr are the children of lca 2 (A).
Proof.Each of the properties is easily verified by inspection of the Make-R ∪ B-compatible and Make-Splittable procedures.For example, point 4 follows from the fact that a node û picked in Make-R ∪ Bcompatible is always chosen as low as possible.This implies that for the newly created component A , and

Split
The next procedure will refine P so that the resulting partition does not overlap in Since by Lemma 3, P is splittable, we can simply intersect each component with R, B and W , to achieve this property.However, we will need to be slightly more careful in order to achieve the approximation guarantee; in particular, we will sometimes need to perform what we call a Special-Split.
procedure Split(P, (R, B, W )) for each multicolored component A do if A is tricolored, and there exists a tricolored triple in A that is compatible then Special-Split(A, P, (R, B, W )) else P ← P \ {A} ∪ {A ∩ R, A ∩ B, A ∩ W } (where empty sets are not added) end if end for end procedure Remark.Our analysis in Section 4 needs the Special-Split, Find-Merge-Pair and Merge-Components procedures only in one (of three) cases that will be described in Lemma 12. Without these procedures, it is trivial to see that the resulting partition is feasible, and we will see in Section 4 that the proof of the approximation ratio is quite simple in these cases.
We now describe the property that the outcome partition of Split will have, which goes beyond merely being R ∪ B-compatible and non-overlapping in We first define that property, and give necessary and sufficient conditions for a partition that does not overlap in V 2 to have this property.Definition 7. Let K ⊆ L. A partition P is K-feasible if for all w ∈ L, P is K ∪ {w}-compatible, and no two components in P overlap in We will simply say P is feasible if it is L-feasible, which we note does indeed coincide with the definition of a feasible solution to MAF.We make two additional remarks about the notion of K-feasibility: • Being K-feasible requires something stronger than simply not overlapping in V 2 ∪ V 1 [K] and Kcompatibility.The stronger compatibility notion will be used in Lemma 7 to show that if P is R ∪ B-feasible, then future iterations of the Red-Blue algorithm will not further subdivide (the partition induced on) the leaves in R ∪ B. This is not necessarily true if P is only R ∪ B-compatible and does not overlap in The converse is not true, however: if The stronger notion of a u being a root-of-infeasibility versus not being L(u)-feasible is needed when we prove the approximation guarantee in Section 4.
The following technical lemma gives conditions to check if a partition does not overlap in Lemma 5. Let P be the partition and (R, B, W ) be the coloring at the start of an iteration.Let P be a refinement of P that does not overlap in V 2 and that is R ∪ B-compatible.
is covered only by components in P that are subsets of W , or that are also components of P.
Proof.Suppose the conditions of the lemma hold for P .First, observe that by (i), P contains at most one component covering lca 1 (R ∪ B).Suppose for a contradiction that A , A ∈ P overlap in Since lca 1 (R ∪ B) was chosen as a lowest root-of-infeasibility, lca 1 (R) and lca 1 (B) were not roots-ofinfeasibility for P.This implies that no two components of , so it must be the case that A and A were both part of a single component in P. Furthermore, P must have been R-compatible and B-compatible, so (A ∪ A ) ∩ R and (A ∪ A ) ∩ B are compatible sets.We will show that these facts imply that if A and First, assume both A and A are unicolored, and thus they are each either red or blue (since otherwise they would not overlap in , x , y ) and similarly lca 1 (x , x ) ≺ lca 1 (x , x , y ).Since {x , x , y , y } is a compatible set, we must also have lca 2 (x , x ) ≺ lca 2 (x , x , y ) and lca 2 (x , x ) ≺ lca 2 (x , x , y ).But then lca 2 (x , x ) is on the path from x to y as well as on the path from x to y .Hence, A and A overlap in lca 2 (x , x ) ∈ V 2 , contradicting that P does not overlap in V 2 .Now, suppose A is unicolored, and A is the unique multicolored component A * , and . Without loss of generality A ⊆ R. Then we still know that {x , x , y } is compatible, and thus that lca 2 (x , x ) ≺ lca 2 (x , x , y ), so that lca Figure 4: Two illustrations of Split(P, (R, B, W )). In the top example }} and Split(P) would simply refine each set of P by intersecting it with the three color classes.The result is that every leaf is a singleton in P .
In the bottom example, lca 2 (x , x ), again contradicting that P does not overlap in V 2 .So it must be the case that lca 2 (A * ) is a descendant of lca 2 (x , x ).But then V 2 [A ] intersects the path from lca 2 (A * ) to lca 2 (R ∪ B).But we already showed above that A ∪ A * was part of a single component in P, which implies that A is not a component of P, contradicting (ii).
We now describe the Special-Split procedure.Recall that this is only called if A is tricolored, and there is at least one tricolored compatible triple in A.
procedure Special-Split(A, P, (R, B, W )) if every tricolored triple in A is compatible then The next lemma states that this ensures the partition resulting after Split is R ∪ B-feasible.Lemma 6.Let P be the partition after Split(P, (R, B, W )). Then P is a refinement of P that is R ∪ Bfeasible.Moreover, Special-Split is applied to at most one component in each iteration of the Red-Blue algorithm, implying that P has at most one multicolored component.
Proof.The fact that P does not overlap in V 2 follows from the fact that every component of P was splittable.
It is also easy to see that every component is R ∪ B ∪ {w}-compatible for all w ∈ L: each component is either unicolored (and thus R ∪ B ∪ {w}-compatible by the fact that the partition is R ∪ B-compatible by Lemma 1), or it is the result of a Special-Split on a component that was already R ∪ B ∪ {w}-compatible for all w ∈ L before the Special-Split.

It remains to show that no two components in
By Lemma 5, it suffices to show P has at most one multicolored component, and that this component, if it exists, is a top component (recall Definition 6).Note that the only possible multicolored components of P are bicolored components created by Special-Split on a component A ∈ P that is tricolored and in which every tricolored triple is compatible.By property 4 of Lemma 4, the only tricolored components that have a compatible tricolored triple are top components, and by Observation 1, the partition at the start of the iteration had at most one tricolored component, and thus there is also at most one tricolored top component in P.So P has at most one multicolored component, which is a top component, and by Lemma 5, this implies P does not overlap in

Find-Merge-Pair and Merge-Components
The astute reader may have noted that the Red-Blue Algorithm sometimes increases the number of components by more than necessary to be R ∪ B-feasible.For example, it follows from the arguments in the proof of the previous lemma that if there is a tricolored component in which every tricolored triple is compatible, then not further subdividing this component would also leave a partition that is R ∪ B-feasible.Find-Merge-Pair and Merge-Components aim to merge two components of the partition produced at the end of Split, so that the partition with the merged components is still R ∪ B-feasible.Find-Merge-Pair thus looks for a pair of components that can be merged, by scanning the components of the current partition, and finding two leaves in R ∪ B that are in different sets of the partition now, but that were in the same component at the start of the current iteration.
procedure Find-Merge-Pair(pairslist, P, (R, B, W )) x 1 and x 2 were in the same component at the start of the current iteration, x 1 and x 2 are in distinct components A 1 and A 2 in P, and Although we could simply merge the components containing x 1 and x 2 for the pair found by Find-Merge-Pair, we will not do so until the very end of the algorithm.The reason we keep such "superfluous" splits is because they will increase the objective value of the dual solution we use to prove the approximation guarantee of 2 (see Section 4).We "reverse" these superfluous splits (i.e., we will merge components) at the end of the algorithm; this is reminiscent of a "reverse delete" in approximation algorithms for network design [12].
procedure Merge-Components(pairslist, P) for each pair (x 1 , x 2 ) in pairslist do Let A 1 and A 2 be the sets in P containing x 1 and x 2 , respectively.
The proof that we will be able to merge the components containing the pair of leaves identified by Find-Merge-Pair at the end of the algorithm will rely on the fact that (i) because the partition is R ∪ B ∪ {w}compatible for any w ∈ L, merging the components containing the identified leaves x 1 , x 2 ∈ R ∪ B cannot increase the number of incompatible triples contained in a component, and (ii) because the partition is R ∪ B-feasible, future iterations of the algorithm will not further refine the partition induced on R ∪ B. This is the reason why we do not allow Find-Merge-Pair to choose leaves in W (and only choosing leaves in R ∪ B is sufficient to prove the claimed approximation guarantee).Lemma 7. Let (R, B, W ) be the coloring during some iteration of the Red-Blue algorithm, let P be the partition at the end of the pass, and let x, x ∈ R ∪ B. If x, x are in the same component of P, then x and x are in the same component in any partition at any later point of the algorithm's execution.
Proof.Let (R , B , W ) be the coloring of the leaves in some later iteration of the algorithm, and suppose for a contradiction that the iteration with coloring (R , B , W ) separates x and x in different components.From a brief consideration of the algorithm, it is apparent that there must exist some û ∈ T 2 such that A ∩ L(û) is multicolored with respect to the coloring (R , B , W ), and A ∩ L(û) contains precisely one of x, x .By relabeling if needed, assume that x ∈ A ∩ L(û) and x ∈ A \ L(û), and let w ∈ A ∩ L(û) be any leaf with a color different from x, and note that lca 2 (x, w) ≺ û ≺ lca 2 (x, x , w). ( Since is a root-of-infeasibility, and hence all leaves in R ∪ B, and in particular x and x , must have the same color in the coloring (R , B , W ). Furthermore, if w has a different color than x and x in (R , B , W ), then w ∈ R ∪ B, and thus lca 2 (x, x ) ≺ lca 2 (x, x , w).But, since P is R ∪ B ∪ {w}-compatible, this implies that if w is in the same component as x and x in (a refinement of) P, then lca 2 (x, x ) ≺ lca 2 (x, x , w), contradicting (1), because only one of lca 2 (x, x ) and lca 2 (x, w) can be strictly below lca 2 (x, x , w).

Correctness of the algorithm
Theorem 8.The Red-Blue Algorithm returns a feasible solution to MAF.
Proof.Let k be the number of pairs in pairslist.We prove the theorem by induction on k.If k = 0, then the algorithm returns the partition obtained at the end of the while-loop, which is feasible by the fact that otherwise lca 1 (L) would be a root-of-infeasibility.
If k > 0, observe that the final partition is the same irrespective of the order in which the pairs in pairslist are considered.We may thus assume without loss of generality that they are considered in the reverse order in which they were added to pairslist.Let P be the partition after the components have been merged for all pairs on pairslist, except the pair (x 1 , x 2 ) that was added to pairslist first.Let P be the partition at the moment when (x 1 , x 2 ) was added to pairslist, and let R, B, W be the three color sets at that moment.Observe that P is a refinement of P, and that, by Lemma 7, P and P induce the same partition of R ∪ B.
Let A 1 , A 2 be the components in P containing x 1 , x 2 respectively.By the choice of x 1 , x 2 , (A 1 ∪ A 2 ) is R ∪ B ∪ {w}-compatible for any w ∈ L, and does not overlap any component of P \ {A 1 , A 2 }.
If A 1 , A 2 are unicolored, they both contain leaves in R ∪ B only, and thus by Lemma 7, P contains components A 1 and A 2 as well.Furthermore, in this case, the set A 1 ∪ A 2 is a subset of R ∪ B and thus the fact that it is R ∪ B ∪ {w}-compatible for any w ∈ L implies it is compatible.The fact that A 1 ∪ A 2 does not overlap any set A ∈ P \ {A 1 , A 2 } implies it also does not overlap any set A ∈ P \ {A 1 , A 2 }, since P is a refinement of P.
If A 1 and A 2 are not both unicolored, observe that only one of A 1 , A 2 is bicolored and contains leaves in B ∪ W , since those are the only type of multicolored components after Split, and P does not overlap in V 1 [R ∪ B] so it can only have one multicolored component.Suppose without loss of generality that A 1 is unicolored and A 2 contains leaves in B ∪ W .By Lemma 7, P contains component A 1 and a component We need to show that A 1 ∪ A 2 is compatible and does not overlap any component in P \ {A 1 , A 2 }.For the latter, suppose in order to derive a contradiction that Since P is a refinement of P, there must exist A ∈ P such that A ⊂ A, and thus To show that A 1 ∪A 2 is compatible, note that A 2 is compatible, and that

Proof of the approximation guarantee
We showed in the previous section that the Red-Blue algorithm returns a feasible solution P. In order to prove that our algorithm achieves an approximation guarantee of 2, we will use linear programming duality.

The linear programming relaxation
Introduce a variable x L for every compatible set L ∈ C, where in an integral solution, x L = 1 indicates that the tree with leaf set L forms part of the solution to MAF.The constraints ensure that in an integral solution, {L : x L = 1} is a partition, and that V [L] ∩ V [L ] = ∅ for two distinct sets L, L with x L = x L = 1.The objective encodes the size of the partition minus 1.
In fact, it will be convenient for our analysis to expand the first set of constraints to contain a constraint for every (not necessarily compatible) set of leaves A, stating that every such set must be intersected by at least one tree in the chosen MAF solution.All these constraints are clearly already implied by the constraints for A a singleton, already present in (LP), but they provide us a more expressive dual.
The dual of (LP ) is We will refer to the left-hand side of the first family of constraints, i.e., v∈V [L]\L y v + A:A∩L =∅ z A , as the load on set L, and denote it by load (y,z) (L).By weak duality, we have that the objective value of any feasible dual solution provides a lower bound on the objective value of any feasible solution to (LP), and hence also on the optimal value of any feasible solution to MAF.Hence, in order to prove that an agreement forest that has |P| components is a 2-approximation, it suffices to find a feasible dual solution with objective value 1 2 (|P| − 1), i.e., for every new component created by the algorithm, the dual objective value should increase by 1  2 (on average).

The dual solution
The dual solution maintained is as follows.Throughout the main loop of the algorithm, z A = 1 if and only if A is a component in P. In the last part of the algorithm, when we merge components according to pairslist, we do not update the dual solution; these operations affect the primal solution (i.e., P) only.Initially, y v = 0 for all v ∈ V 1 ∪V 2 .At the start of each iteration, we decrease y u by 1, where u = lca 1 (R∪B).Whenever in the algorithm we choose a component A and a node û ∈ V 2 [A], and separate the component A into A ∩ L(û) and A \ L(û), we decrease y û by 1.To be precise this happens in Make-R ∪ B-compatible, Make-splittable and in one case in Special-Split (where we actually further refine A ∪ L(û)).The lines where such nodes are chosen are indicated by in the description of the algorithm and the procedures it contains.
Lemma 9.The dual solution maintained by the algorithm is feasible.
Proof.We prove the lemma by induction on the number of iterations.Initially, z A = 0 for all A = L and z L = 1 and hence every compatible set L has a load of 1.
At the start of an iteration, we decrease y lca1(R∪B) by 1, thus decreasing the load by 1 on any multicolored compatible set L. We show that the remainder of the iteration increases the load by at most 1 on a multicolored compatible set and that it does not increase the load on any unicolored compatible set.
First, observe that Make-R ∪ B-compatible and Make-Splittable do not increase the load on any set: Separating A into A ∩ L(û) and A \ L(û) increases the load on sets L that intersect both A ∩ L(û) and A \ L(û), since z A gets decreased from 1 to 0, and z A∩L(û) and z A\L(û) increase from 0 to 1.However, in this case û ∈ V [L], and thus decreasing y û by 1 ensures that the load on L does not increase.
To analyze the effect of Split, we use the following two claims.
Claim 10.In the procedure Split(P, (R, B, W )) the load on any compatible set L is increased by at most the number of components A ∈ P such that L ∩ A is multicolored.
Proof of Claim: If the load on L is increased because Split splits a bicolored component A into two unicolored components, then L must intersect both new components, so L ∩ A is bicolored (and thus multicolored).
Consider the case where the load on L is increased because a tricolored component A is split into A ∩ R, A ∩ B and A ∩ W .This split happens when all tricolored triples in A are incompatible.Therefore L ∩ A cannot be tricolored, and the load is increased by 1.And again L ∩ A is multicolored.
Suppose the load on L is increased because Special-Split(A, P, (R, B, W )) is executed for a component A. We consider the two cases.Either A is split into two components, one of which contains all red leaves in A. The load on a set L thus increases by 1 if L ∩ A is multicolored and L ∩ A ∩ R = ∅ and by 0 otherwise.If A is split into four components; we think of this as first splitting A into A ∩ L(û) and A \ L(û), and then splitting A ∩ L(û) by intersecting with R, B and W . Since y û is decreased by 1, splitting A into A ∩ L(û) and A \ L(û) does not affect the load on any set L. Splitting A ∩ L(û) by intersecting with R, B, W increases the load on L by 1 if L ∩ A ∩ L(û) is bicolored and by 2 if it is tricolored; note however that the latter is impossible, since û = lca 2 (A ∩ (R ∪ B)), so any tricolored triple in A ∩ L(û) must be incompatible.So the load on L again increases by at most 1 if A ∩ L is multicolored.Claim 11.If L is compatible, and A and A do not overlap in V 2 , then L ∩ A and L ∩ A cannot both be multicolored.
Proof of Claim: Since V 2 [A] and V 2 [A ] are disjoint, it must be the case that lca 2 (x, y) ≺ lca 2 (x, y, x ) for all x, y ∈ A and x ∈ A , or lca 2 (x , y ) ≺ lca 2 (x, x , y ) for all x , y ∈ A and x ∈ A (or both).Hence, if L ∩ A and L ∩ A are both multicolored sets, then there exists x, y, x , y ∈ L where x, y have different colors, x , y have different colors, lca 2 (x, y) ≺ lca 2 (x, y, x ), and lca 2 (x, y) ≺ lca 2 (x, y, y ).We claim this implies {x, y, x , y } is incompatible.
Clearly one of x, y has the same color as one of x , y .Suppose first that either red or blue is a shared color.Without loss of generality, we may assume that x and x are both red; y is then either blue or white.x and x being red implies lca 1 (x, x ) ≺ lca 1 (x, y, x ), which, since lca 2 (x, y) ≺ lca 2 (x, y, x ), shows that {x, x , y} is an incompatible triple.
So suppose that white is the only shared color, and that x and x are both white.Then either y is red and y is blue, or vice versa.This implies lca 1 (y, y ) ≺ lca 1 (x, y, y ), and so, since lca 2 (x, y) ≺ lca 2 (x, y, y ), this implies {x, y, y } is an incompatible triple.
It follows immediately from the two claims that Split increases the load by at most 1 on any multicolored compatible set and that it does not increase the load on any unicolored set, which completes the proof of the lemma.

The primal and dual objective values
Let P, pairslist be the partition and pairslist at the end of an iteration, and let D = v∈V \L y v + |P| − 1 be the objective value of the dual solution at this time.In this section, we show that our algorithm maintains the invariant that 2D ≥ (|P| − 1 − |pairslist|) . ( Observe that the approximation guarantee immediately follows from this inequality, since the objective value of the algorithm's solution is P − 1 − |pairslist| (where P, pairslist are the partition and pairslist at the end of the final iteration), and by weak duality D gives a lower bound on the optimal value of the MAF instance.
To prove that the algorithm maintains the invariant, we will show that a given iteration increases the left-hand side of (2) by at least as much as the right-hand side.We let ∆D be the change in the dual objective during the iteration and ∆P be the increase in the number of components less the number of pairs added to pairslist (either 0 or 1) during the current iteration.
Since at the start of the algorithm, the partition consists of exactly one component, and In what follows, we use the following to refer to the state of the partition at various points in the current iteration: P (0) at the start; P (1) after Make-R ∪ B-compatible; P (2) after Make-Splittable; and P (3)  after Split.
We begin by showing that the coloring (R, B, W ) and the partition P (0) satisfies the conditions of one of three cases.
Lemma 12.Given an infeasible partition P (0) that does not overlap in T 2 , let u ∈ V 1 be a lowest root-ofinfeasibility, and let u and u r be u's children in T 1 .Let R = L(u r ), B = L(u ), and W = L \ (R ∪ B).Then P (0) is R-compatible and B-compatible and satisfies exactly one of the following three additional properties: Case 1. P (0) has exactly one multicolored component, say A 0 , where A 0 is tricolored, not R ∪ B-compatible, and there exists Case 2. P (0) has exactly two multicolored components, say A B , A R , where Case 3. P (0) has exactly one multicolored component, say A 0 , where A 0 is tricolored, R ∪ B-compatible and A 0 contains no compatible tricolored triple.
We will see in the proof below that Case 1, 2 and 3 correspond to a lowest root-of-infeasibility satisfying (a), (b) and (c) respectively in Definition 4. We refer the reader to Figure 1 for an illustration of the three cases.
Proof.Observe that if P (0) is infeasible, then the root of T 1 , i.e., lca 1 (L) is a root-of-infeasibility, and that any v ∈ L is not a root-of-infeasibility.Hence, u is well-defined and R and B are non-empty.Note that P (0) is R-compatible and B-compatible, since u's children are not root-of-infeasibility.
We will show that if u satisfies condition (a) in the definition of root-of-infeasibility, then the conditions of Case 1 are satisfied, if (b) holds, the conditions of Case 2 are satisfied, and if (c) holds, but not (a), then the conditions of Case 3 are satisfied.
We start with (b).Observe that, because P (0) is R-compatible and B-compatible, there must be at least two multicolored components if (b) holds.If there are two multicolored components, both containing, say, red leaves, then they overlap in u r = lca 1 (R), which implies u r is a root-of-infeasibility, contradicting the choice of u.Similarly, there is at most one multicolored component containing blue leaves.Hence, the conditions of Case 2 are satisfied.
If (b) does not hold, then there is at most one multicolored component; the conditions in (a) and (c) both imply there must be at least one (and thus there is exactly one), which we will call A 0 .We let If (a) holds, then A 0 is not R ∪ B-compatible, and thus R 0 = ∅, B 0 = ∅.Assume, in order to derive a contradiction, that A 0 ⊆ L(û).Observe that, because A 0 is not R ∪ B-compatible, lca 2 (R 0 ) = û or lca 2 (B 0 ) = û.Suppose the former without loss of generality.But then lca 1 (R 0 ) is a root-of-infeasibility satisfying (c) which is a descendant of u thus contradicting the choice of u: A 0 \L(lca Suppose now (c) holds, but not (a), i.e., P (0) is R ∪ B-compatible.Thus A 0 must be R ∪ B-compatible and A 0 \ (R 0 ∪ B 0 ) = ∅.Assume without loss of generality that R 0 = ∅, and note that lca 1 (R 0 ) is a descendant of u, and that, if B 0 = ∅, then (c) holds for lca 1 (R 0 ), contradicting the choice of u.Hence, A 0 is tricolored.Since A 0 is R ∪ B-compatible, lca 2 (R 0 ) and lca 2 (B 0 ) must be descendants of the distinct children of û, or the children itself.Furthermore, the fact that implies that all white leaves are descendants of û as well, and thus any tricolored triple of leaves in A 0 is incompatible.Thus, if (c) holds but not (a), the conditions for Case 3 are satisfied.
Recall that the coloring is defined only at the start of the iteration.The lemma ensures that the partitions during the iteration always have either one (in Case 1 and 3) or two (in Case 2) top components.
For Cases 2 and 3, the analysis is quite simple.
Proposition 13.Let the initial partition P (0) and coloring (R, B, W ) satisfy the conditions of Case 2 or 3 in Lemma 12. Then 2∆D ≥ ∆P .
In addition, we note that To see this, note that at the start of the iteration, the dual objective value is reduced by 1 when y u is decreased by 1 for u = lca 1 (R ∪ B).Make-splittable does not change the dual objective value, because, even though |P| increases by 1 every time the number of components increases by 1, v y v decreases by 1 as well.Finally, since Split will not perform any Special-Split, the increase in the dual objective value due to Split is equal to the increase in the number of components due to Split, which is |P (3) | − |P (2) |.
Note that the size of pairslist may increase but will never decrease, and thus = 2∆D by (5).
We now prove a similar proposition for Case 1, the proof of which is more involved.
Proposition 14. Suppose the initial partition P (0) and coloring (R, B, W ) satisfy the conditions of Case 1 in Lemma 12. Then 2∆D ≥ ∆P .
Proof.In Case 1, we start with one tricolored component A 0 , which is not R ∪ B-compatible.Let x W be a white leaf in A 0 that is not a descendant of lca 2 (A 0 ∩ (R ∪ B)), which exists by the definition of Case 1.By property 6 in Lemma 4, x W is also contained in the top component of P (3) , and by property 2 in Lemma 4, the top component is multicolored.Therefore, the top component of P (2) is either bicolored, or it is tricolored and a Special-Split is performed on the top component.Let χ be an indicator variable that is 1 if the top component in P (2) is tricolored and has a tricolored triple that is incompatible.Let t be the number of tricolored components in P (2) that are not top components.We claim that Indeed, if χ = 0, the top component is divided into two components by Split, and if χ = 1 it is subdivided into four components.Thus splitting the top component increases the number of components by 1 + 2χ.By property 2 of Lemma 4, P (2) has |P (2) | − |P (0) | multicolored components that are not top components, and by property 4, each of the tricolored components that are not top components do not require a Special-Split and are thus subdivided into three components by Split.Hence, splitting the components that are not top components increases the number of components by |P (2) | − |P (0) | + t.Next, we analyze the increase in the dual objective.We claim that To see this, note that the dual objective is decreased by 1 when we decrease y lca1(R∪B) by 1 at the start of the iteration.The dual objective is not affected by Make-R ∪ B-compatible and Make-Splittable.Finally, if χ = 0, the increase in the dual objective due to Split is equal to the increase in the number of components |P (3) | − |P (2) |.If χ = 1, the same holds, but Special-Split on the top component also decreases y û0 by 1.So we get that = 2∆D + 1 − t by (7).
Recall that ∆P is equal to |P (3) | − |P (0) | minus the number of pairs added to pairslist in the current iteration.Hence, to conclude that ∆P ≤ 2∆D, we need to show that if t = 0, then a pair is added to pairslist by Find-Merge-Pair.
We will say that a component A is able to reach û if û ∈ V 2 [A] or if lca 2 (A) ≺ û and all intermediate nodes on the path from lca 2 (A) to û are not covered by any component in P (3) .The following lemma (which is actually valid in general, and not only for Case 1) enumerates precisely the situations when a merge is possible.
Lemma 15.Let A 0 ∈ P (0) , and let Q denote the set of components in P (3) that are contained in A 0 .Then there exist a pair of elements in A 0 that can be added to pairslist if and only if at least one of the following is true: (a) Q contains a bicolored component.
(b) There is a node û ∈ V 2 that can be reached by two red components or two blue components in Q.
(c) There is a node û ∈ V 2 that can be reached by a red and a blue component in Q, but is not covered by these components.Furthermore, the node û must satisfy that the nodes on the path from û to lca 2 (A 0 ) are not covered by any red or blue component in Q.
Proof.By the definitions of Split and Special-Split, a multicolored component in P (3)  The same applies if A and A are both blue components in Q.
(c) If Q does not contain a bicolored component A * , suppose there exist A, A ∈ Q with A red and A blue such that (i) there exists û ) that can be reached by both A and A ; and (ii) the nodes on the path from û to lca 2 (A 0 ) are not in V 2 [A ] for any A ⊆ W . Then merging A and A gives a new partition that does not overlap in V 2 and the new component A ∪ A , is R ∪ B-compatible by (i).Thus the new partition is R ∪ B ∪ {w}-compatible for any w ∈ L. The unique bicolored component A ∪ A in this new partition satisfies that any node on the path from û = lca 2 (A ∪ A ) to lca 2 (A 0 ) is not covered by a component that is not white.The components of the partition that overlap a node on the path from lca 2 (A 0 ) to lca 2 (R ∪ B) were not changed in the current iteration.Therefore, by Lemma 5, the new partition does not overlap in Hence, merging A and A gives a new partition that is R ∪ B-feasible.
We note that the above three cases encompass all possible merge opportunities within Q.If two components cannot reach the same node û ∈ V 2 , then merging them gives a partition that overlaps in V 2 .If a red and blue component A and A can reach the same node û ∈ V 2 and this node is covered by either A or A , then A ∪ A is not R ∪ B-compatible.And if a red and blue component A and , but some node on the path from û to lca To see this, assume A is red (the blue case is analogous) and let v be the node in V 2 [A ] closest to û on the path from û to lca 2 (A 0 ).Then v = lca 2 (A ∪ (A ∩ L(v)) ≺ lca 2 (A ), and since A ∪ A are compatible in R, we should also have lca 1 (A ∪ (A ∩ L(v)) ≺ lca 1 (A ).Thus A and A overlap on a node on the path from lca 1 (A) to lca 1 (R ∪ B).
We are now ready to complete the proof of Proposition 14, by showing that if t = 0, then at least one of (a), (b) and (c) in Lemma 15 holds for P (3) .Suppose (a) does not hold, i.e., P (3) has only unicolored components.Let û be the last node chosen in Make-R ∪ B-compatible to subdivide the top component.The existence of û follows since P (1) = P (0) as we observed above.Let A ⊂ L(û) be the non-top component added to the partition at this point.Since t = 0, we have that A is bicolored by property 2 in Lemma 4. Split will split A into A ∩ R and A ∩ B, and by property 5 in Lemma 4, node û itself is not covered by any component of P (3) and it can be reached by red component A ∩ R and blue component A ∩ B. So if there is no node on the path in T 2 from û to lca 2 (A 0 ) that is covered by a red or blue component in P (3) , then A ∩ R and A ∩ B give a pair that can be added to pairslist according to (c).
So suppose that there is a node on the path from û to lca 2 (A 0 ) that is covered by a (say) red component A R in P (3) ; without loss of generality v is the node closest to û such that v ∈ V 2 [A R ] for some red component A R .If A ∩ R can reach v then v can be reached by two red components, so we can add a pair to pairslist according to (b).
Otherwise, let ŵ be the node closest to v on the path from û to v that is covered by a white component A W .By definition of ŵ, all nodes on the path from ŵ to v are not covered by any component in P (3) .Observe that • A W and A R must have been part of the top component of P (1) , by definition of û.
• A W and A R cannot have been part of the top component of P (2) : as we observed above, the top component of P (2) contains a white leaf x W that is not a descendant of lca 2 (A 0 ∩(R∪B)), so A W ∪{x W } overlaps v, and since A R also overlaps v, the top component of P (2) would not be splittable if it contained A R ∪ A W , contradicting Lemma 3.
• A W was part of non-top component A in P (2) , which contained red and white leaves: by the second observation, A W must have been part of a non-top component A , which was multicolored by property 2 of Lemma 4. Since A and A R were part of the same component of P (1) by the first observation, A ∪ A R must be R ∪ B-compatible by Lemma 1.This implies A does not contain any blue leaves, since otherwise such a blue leaf x B , and a red leaf

and thus the triple would be incompatible, contradicting that
Thus, A = A W ∪ (A ∩ R), and by property 5 in Lemma 4, the component A ∩ R in P (3) can reach lca 2 (A ).Since ŵ ≺ lca 2 (A ), lca 2 (A ) is on the path from ŵ to v.But then A ∩ R can reach v, so A R and A ∩ R give a pair to be added to pairslist according to (b).

A compact formulation of the LP
Here we give a compact formulation for (LP).This shows that it can be optimized efficiently.While this is not needed in our algorithm, it is possible that an LP-rounding based algorithm could achieve a better approximation guarantee, in which case this formulation will be of use.Moreover, the LP explicitly encodes the structure of compatible sets in a way that (LP) does not; we believe this may provide additional structural insights in the future.
We remark that (LP) can also be shown to be polynomially solvable by providing a separation oracle for the dual.The dual of (LP) is similar to (5), the dual of (LP ), except that z is indexed only by singletons and not arbitrary subsets of L. This dual has a polynomial number of variables, but an exponential number of constraints.By the equivalence of separation and optimization, it suffices to provide a separation oracle for this dual.The following problem subsumes this separation problem: given some (positive or negative) weights y on the nodes of V , find a compatible subset L ∈ C which maximizes v∈V [L] y v .This is a weighted variant of the maximum agreement subtree problem.Similar to the usual (unweighted) version [24], this can be solved in polynomial time via dynamic programming.
Assume for convenience that L = {1, 2, . . ., n}.We will deviate from the notational conventions in the previous sections, and use i and j to denote leaves, and we will use t ∈ {1, 2} to denote the indices of the two input trees.
Consider a set L ⊆ L, and the tree T t [L] it induces in T t for t ∈ {1, 2}.We can identify each internal node u of T t that has two children in T t [L] by a pair consisting of the smallest leaf in L in the subtree below {r ∈ Z : lca t (r) = v}.
Lemma 17.This LP is equivalent to (LP).
Proof.By Lemma 16, (LP -2) and (LP -3) ensure y ∈ C F and thus we can expand y = L∈C:|L|≥2 x L χ F (L) for x ≥ 0. Then taking x L for |L| = 1 as defined by (LP -4), we ensure that L∈C:i∈L x L = 1 for all i ∈ L. Constraint (LP -5) becomes L∈C:v∈L x L ≤ 1 for all non-leaves v.And for r ∈ Z \ Z L , where rt(F ) denotes the root of F .So the objective becomes L∈C x L − 1.Thus, this formulation is equivalent to (LP).

For any w
. Otherwise, u is not a root-of-infeasibility, and we finish our consideration of u.
Once we have determined the coloring (R, B, W ), we compute |A ∩ C| for each component A ∈ P and C ∈ {R, B, W }. We also compute three additional labels for each node û ∈ V 2 : s C (û) = |A û ∩ L(û) ∩ C| for C ∈ {R, B, W }. This information can be determined by a bottom-up traversal of T 2 in O(n) time.We assume this information is updated whenever the partition is refined.

Make-R ∪ B-compatible
Consider the nodes of T 2 in bottom-up order, until we find a node û such that both s B (û) > 1 and s

Make-Splittable
We again consider the nodes in T 2 in bottom-up order.For any node û with A û = ∅, using s C (û) for C ∈ {R, B, W }, we can check in O(1) time whether A û ∩ L(û) is bicolored, and that for any

Split
Note that a regular split of a component A can be done in O(n) time, by simply checking the color of each leaf in A and partitioning A accordingly.We now show how to check if A needs a Special-Split (and if so which of the two possible refinements is applied) by considering the nodes in V 2 [A] in bottom-up order.
If A is tricolored, then the fact that A is R∪B-compatible and splittable implies that there exist ûR and ûB that are covered by A and for which A ∩ L(û R ) = A ∩ R and A ∩ L(û B ) = A ∩ B. Using a bottom-up traversal of V 2 will find ûR and ûB (they are the first nodes v encountered such that A v = A and s C (v) = |A ∩ C| for C = R and B respectively).
Given ûR and ûB , we check if a Special-Split is required, by considering û = lca 2 (A ∩ (R ∪ B)) = lca 2 (û R , ûB ); a Special-Split is required exactly if s(lca 2 (û R , ûB )) < |A|, since in that case any x W ∈ A \ L(lca 2 (û R , ûB )) forms a compatible triple with any x R ∈ A∩R, x B ∈ A∩B.If, in addition, s W (lca 2 (û R , ûB )) = 0, we know that every tricolored triple in A is compatible.

Find-Merge-Pair
We need to determine if there exist two components (both intersecting R ∪ B) that can be merged, in time O(n).If such components are found, then we can take a non-white leaf in each component and add this pair to pairslist.Recall Lemma 15, which enumerates all possible situations where a potential merge may exist.
(a) P has a bicolored component.This component must have been created by an application of Special-Split, splitting some component A ∪ A * ∈ P (2) into A and A * .As discussed in the proof of Lemma 15, simply undoing this split is a valid merge.Since Special-Split is invoked at most once per iteration, we can simply add a pair to pairslist during Special-Split.
(b) There is a node û ∈ V 2 that can be reached by two red or two blue components that were part of the same component at the start of the current iteration.By Lemma 12 (and property 1 of Lemma 4), any two components that are not white that were created in the current iteration must have been part of the same partition at the start of the iteration.We may assume that we can check for each component in constant time whether it was created in the current iteration.
We work bottom-up in T 2 , and set B û to be the set of red and blue components that were created in the current iteration, and that can reach û for every û ∈ V 2 .If B û contains two components of the same color, these two components can be merged, and we terminate.
Note that if B û ever contains three components, we will have found a merge and the algorithm will terminate.This ensures that we can compute this for û in constant time, given the values of A û and B û1 and B û2 for the children of û.
(c) There is a node û ∈ V 2 that can be reached by a red and a blue component that were part of the same component A 0 at the start of the current iteration, but is not covered by these components.Furthermore, the node û must satisfy that the nodes on the path from û to lca 2 (A 0 ) are not covered by any red or blue component.Note that by Lemma 12, A 0 is the only component that was modified in the current iteration, so for this second condition we can simply check that no node on the path from û to the root of V 2 is covered by a red or blue component that was created in the current iteration.
If we did not find two components of the same color that can be merged, we have found B û for every û ∈ V 2 , where |B û| ≤ 2. We now work top-down in T 2 .If we encounter a node û that is covered by a red or blue component that was created in the current iteration, we stop and do not consider the descendants of û (since for any such a descendant, û is on its path to lca 2 (A 0 )).If we encounter a node û such that |B û| = 2 and û is not covered by any component, the two components in B û can be merged, and we may terminate.

B Integrality gap lower bounds
We show a lower bound on the integrality gap of 16  5 for the integer linear program formulation of Wu [28].Recall that a solution to MAF can be viewed as the leaf sets of the trees in a forest, obtained by deleting edges from the input trees.The formulation has binary variables x e for every edge e ∈ T 1 , indicating whether e is deleted from T 1 .We use P (i, j) to denote the set of edges in T 1 on the path between leaves i and j, and P 2 (i, j) to denote the set of edges in T 2 on the path between leaves i and j.Wu's integer linear program [28] is given by: minimize e x e s.t.e∈P (i,j)∪P (i,k)∪P (j,k) x e ≥ 1 for all incompatible triples i, j, k e∈P (i,j) x e + e∈P (k, ) x e ≥ 1 for all two pairs (i, j) and (k, ) for which P (i, j) ∩ P (k, ) = ∅, and P 2 (i, j) ∩ P 2 (k, ) = ∅ The first family of constraints ensures that at least one edge of the paths between i and j, i and k, and j and k has to be deleted for each inconsistent triple i, j and k.The second family of constraints ensures that at least one edge is deleted for every pair of paths between i and j, and k and that are disjoint in T 1 , but for which the corresponding paths in T 2 are not disjoint.
Lemma 18.The integrality gap of the integer linear program of Wu [28] is at least 16  5 .Proof.Let n = 2 k for some k even.We label each internal node in both T 1 and T 2 with a binary string: the roots get the empty string as label, and given an internal node u its left child gets u's label with a "0" appended, and its right child gets u's label with a "1" appended.In T 1 , the leaves are labeled in the same way as the internal nodes, with a binary string of length k.In T 2 , the binary string is reversed to give the label of the leaf.For example, the leftmost leaf (of both trees) has label 00 • • • 0, and the leaf to the right of it has label 0 • • • 01 in T 1 , and 10 Consider the internal nodes whose label is a string of length strictly less than k/2; there are exactly 2 k/2 − 1 = √ n − 1 such nodes in each tree.We claim that any component A must cover at least |A| − 1 of these internal nodes.To see this, consider the set of internal nodes in V t that have two children in the subtree of T t induced by A for t = 1, 2. We will call such nodes bifurcating.Observe that there are 2(|A| − 1) such

P
← {L}.pairslist ← ∅. while P is not feasible do Let u ∈ T 1 be a lowest root-of-infeasibility, with children u and u r .Let R = L(u r ), B = L(u ) and W = L \ (R ∪ B).
2) holds before the first iteration.So to show(2), it suffices to show that 2∆D ≥ ∆P(3)for any iteration.
must be a top component with blue and white leaves created by applying Special-Split to a tricolored component.By Lemma 6, there is at most one such multicolored component; if it exists, call it A * .(a)IfA* exists, then let A ∪ A * be the tricolored component from which Special-Split formed a red component A and the bicolored component A * .Then we can merge A and A * to obtain a new partition that is R ∪ B-feasible: it is clear that undoing the Special-Split yields a partition that does not overlap any other component of P inV 2 .The new component A ∪ A * is R ∪ B ∪ {w}-compatible since A ∪ A * is R ∪ B-compatible and every tricolored triple in A ∪ A * is compatible.Since the new unique bicolored component is a top component, by Lemma 5, the new partition also does not overlap in V 1 [R ∪ B].(b) If Q does not contain a bicolored component A * , suppose A, A ∈ Q are distinct red components in Q so that A and A can both reach the same node û in V 2 .Then merging A and A gives a new partition that does not overlap in V 2 , and which has no multicolored components.Since A 0 ∩ R is compatible, so is A ∪ A .By Lemma 5 the new partition does not overlap in V 1 [R ∪ B].Hence, merging A and A gives a new partition that is R ∪ B-feasible.