Independent Feedback Vertex Set for $P_5$-free Graphs

The NP-complete problem Feedback Vertex Set is that of deciding whether or not it is possible, for a given integer $k\geq 0$, to delete at most $k$ vertices from a given graph so that what remains is a forest. The variant in which the deleted vertices must form an independent set is called Independent Feedback Vertex Set and is also NP-complete. In fact, even deciding if an independent feedback vertex set exists is NP-complete and this problem is closely related to the $3$-Colouring problem, or equivalently, to the problem of deciding whether or not a graph has an independent odd cycle transversal, that is, an independent set of vertices whose deletion makes the graph bipartite. We initiate a systematic study of the complexity of Independent Feedback Vertex Set for $H$-free graphs. We prove that it is NP-complete if $H$ contains a claw or cycle. Tamura, Ito and Zhou proved that it is polynomial-time solvable for $P_4$-free graphs. We show that it remains polynomial-time solvable for $P_5$-free graphs. We prove analogous results for the Independent Odd Cycle Transversal problem, which asks whether or not a graph has an independent odd cycle transversal of size at most $k$ for a given integer $k\geq 0$. Finally, in line with our underlying research aim, we compare the complexity of Independent Feedback Vertex Set for $H$-free graphs with the complexity of $3$-Colouring, Independent Odd Cycle Transversal and other related problems.


Introduction
Many computational problems in the theory and application of graphs can be formulated as modification problems: from a graph G, some other graph H with a desired property must be obtained using certain permitted operations. The number of graph operations used (or some other measure of cost) must be minimised. The computational complexity of a graph modification problem depends on the desired property, the operations allowed and the possible inputs; that is, we can prescribe the class of graphs to which G must belong. This leads to a rich variety of different problems, which makes graph modification a central area of research in algorithmic graph theory.
A set S of vertices in a graph G is a feedback vertex set of G if removing the vertices of S results in an acyclic graph, that is, the graph G − S is a forest. The Feedback Vertex Set problem asks whether or not a graph has a feedback vertex set of size at most k for some integer k ≥ 0 and is a well-known example of a graph modification problem: the desired property is that the obtained graph is acyclic and the permitted operation is vertex deletion. The directed variant of Feedback Vertex Set was one of the original problems proven to be NP-complete by Karp [25]. The proof of this implies NP-completeness of the undirected version even for graphs of maximum degree 4 (see [16]). We refer to the survey of Festa et al. [15] for further details of this classic problem.
In this paper, we consider the problem where we require the feedback vertex set to be an independent set. We call such a set an independent feedback vertex set. We have the following decision problem.

Independent Feedback Vertex Set
Instance: a graph G and an integer k ≥ 0. Question: does G have an independent feedback vertex set of size at most k?
Many other graph problems have variants with an additional constraint that a set of vertices must be independent. For example, see [17] for a survey on Independent Dominating Set, and [32] for Independent Odd Cycle Transversal, also known as Stable Bipartization. An independent odd cycle transversal of a graph G is an independent set S such that G − S is bipartite, and the latter problem is that of deciding whether or not a graph has such a set of size at most k for some given integer k.
We survey known results on Independent Feedback Vertex Set below.

Related Work
Not every graph admits an independent feedback vertex set (consider complete graphs on at least four vertices). Graphs that do admit an independent feedback vertex set are said to be near-bipartite, and we can ask about the decision problem of recognising such graphs.

Near-Bipartiteness
Instance: a graph G. Question: is G near-bipartite (that is, does G have an independent feedback vertex set)?
Near-Bipartiteness is NP-complete even for graphs of maximum degree 4 [43] and for graphs of diameter 3 [5] (see [4] for a proof). Hence, by setting k = n, we find that Independent Feedback Vertex Set is NP-complete for these two graph classes. The Independent Feedback Vertex Set problem is even NP-complete for planar bipartite graphs of maximum degree 4 (see [42]). As bipartite graphs are near-bipartite, this result shows that there are classes of graphs where Independent Feedback Vertex Set is harder than Near-Bipartiteness. To obtain tractability results for Independent Feedback Vertex Set, we need to make some further assumptions.
One way is to consider the problem from a parameterized point of view. Taking k as the parameter, Misra et al. [34] proved that Independent Feedback Vertex Set is fixed-parameter tractable by giving a cubic kernel. This is in line with the fixed-parameter tractability of the general Feedback Vertex Set problem (see [26] for the fastest known FPT algorithm). Later, Agrawal et al. [1] gave a faster FPT algorithm for Independent Feedback Vertex Set and also obtained an upper bound on the number of minimal independent feedback vertex sets of a graph.
Another way to obtain tractability results is to restrict the input to special graph classes in order to determine graph properties that make the problem polynomialtime solvable. We already mentioned some classes for which Independent Feedback Vertex Set is NP-complete. In a companion paper [4], we show that the problem is polynomial-time solvable for graphs of diameter 2, and as stated above, the problem is NP-complete on graphs of diameter 3. Tamura et al. [42] showed that Independent Feedback Vertex Set is polynomial-time solvable for chordal graphs, graphs of bounded treewidth and for cographs. The latter graphs are also known as P 4 -free graphs (P r denotes the path on r vertices and a graph is H-free if it has no induced subgraph isomorphic to H), and this strengthened a result of Brandstädt et al. [7], who proved that Near-Bipartiteness is polynomial-time solvable for P 4 -free graphs.

Our Contribution
The Independent Feedback Vertex Set problem is equivalent to asking for a (proper) 3-colouring of a graph, such that one colour class has at most k vertices and the union of the other two induces a forest. We wish to compare the behaviour of Independent Feedback Vertex Set with that of the 3-Colouring problem. It is well known that the latter problem is also NP-complete [30] in general and polynomialtime solvable on many graph classes (see, for instance, the surveys [19,39]). We also observe that 3-Colouring is equivalent to asking whether or not a graph has an independent odd cycle transversal (of any size). However, so far very few graph classes are known for which Independent Feedback Vertex Set is tractable and our goal is to find more of them. For this purpose, we consider H-free graphs and extend the result [42] for P 4 -free graphs in a systematic way.
In Section 2, we consider the cases where H contains a cycle or a claw. We first prove that Near-Bipartiteness, and thus Independent Feedback Vertex Set, is NP-complete on line graphs, which form a subclass of the class of claw-free graphs. We then prove that Independent Feedback Vertex Set is NP-complete for graphs of arbitrarily large girth. Together, these results imply that Independent Feedback Vertex Set is NP-complete for H-free graphs if H contains a cycle or claw. Hence, only the cases where H is a linear forest, that is, a disjoint union of paths, remain open. In particular, the case where H is a single path has not yet been resolved. Due to the result of [42] for P 4 -free graphs, the first open case to consider is when H = P 5 (see also Fig. 1). The class of P 5 -free graphs is a well-studied graph class. For instance, Hoàng et al. [23] proved that for every integer k, k-Colouring is polynomial-time solvable for P 5 -free graphs, whereas Golovach and Heggernes [18] showed that Choosability is fixed-parameter tractable for P 5 -free graphs when parameterized by the size of the lists of admissible colours. Lokshantov et al. [29] solved a long-standing open problem by giving a polynomial-time algorithm for Independent Set restricted to P 5 -free graphs (recently, their result was extended to P 6 -free graphs by Grzesik et al. [21]).

P4 P5
Our main result is that Independent Feedback Vertex Set is polynomialtime solvable for P 5 -free graphs. This is proved in Sections 3 and 4: in Section 3 we give a polynomial-time algorithm for Near-Bipartiteness on P 5 -free graphs, and in Section 4 we show how to extend this algorithm to solve Independent Feedback Vertex Set in polynomial time for P 5 -free graphs.
In Section 5 we consider the related problem Independent Odd Cycle Transversal. We prove that all our results for Independent Feedback Vertex Set also hold for Independent Odd Cycle Transversal.
In Section 6, we compare the complexities of Independent Feedback Vertex Set and Independent Odd Cycle Transversal for H-free graphs with the complexity of 3-Colouring and several other related problems, such as Feedback Vertex Set, Vertex Cover, Independent Vertex Cover and Dominating Induced Matching. We also survey some related open problems.

Hardness When H Contains a Cycle or Claw
Before stating the results in this section, we first introduce some necessary terminology. The line graph L(G) of a graph G = (V, E) has the edge set E of G as its vertex set, and two vertices e 1 and e 2 of L(G) are adjacent if and only if e 1 and e 2 share a common end-vertex in G. The claw is the graph shown in Fig. 2. It is well known and easy to see that every line graph is claw-free. A graph is (sub)cubic if every vertex has (at most) degree 3.
We first prove that Near-Bipartiteness is NP-complete for line graphs. It was already known that Feedback Vertex Set is NP-complete for line graphs of planar cubic bipartite graphs [35]. Theorem 1. Near-Bipartiteness is NP-complete for line graphs of planar subcubic bipartite graphs.
Proof. As the problem is readily seen to be in NP, it suffices to prove NP-hardness. We reduce from the Hamilton Cycle Through Specified Edge problem. Given a graph G and an edge e of G, this problem asks whether G has a Hamilton cycle through e. Labarre [28] observed that Hamilton Cycle Through Specified Edge is NP-complete for planar cubic bipartite graphs by noting that it follows easily from the analogous result of Akiyama et al. [2] for Hamilton Cycle. Let (G, e) be an instance of Hamilton Cycle Through Specified Edge. By the aforementioned result, we may assume that G is a planar cubic bipartite graph. Let u 1 and u 2 be the two end-vertices of e. Delete the edge u 1 u 2 and add two new vertices v 1 and v 2 , and two new edges e 1 = u 1 v 1 and e 2 = v 2 u 2 . Let G be the resulting graph. We note that both v 1 and v 2 have degree 1 in G ′ , whereas every other vertex of G ′ has degree 3. Hence G ′ is subcubic. Since G is planar and bipartite, it follows that G ′ is planar and bipartite. Moreover, we make the following observation. Let n be the number of vertices in G. Then the number of vertices in G ′ is n+2, meaning that a Hamilton path in G ′ has n + 1 edges. Moreover, as G is cubic, G has 3 2 n edges, so G ′ has 3 2 n + 1 edges, implying that L(G ′ ) has 3 2 n + 1 vertices. Furthermore, e 1 and e 2 have degree 2 in L(G ′ ) and all other vertices in L(G ′ ) have degree 4, so L(G ′ ) has maximum degree at most 4. Claim 2. The graph G ′ has a Hamilton path from v 1 to v 2 if and only if L(G ′ ) is near-bipartite. To prove Claim 2, first suppose that G ′ has a Hamilton path P from v 1 to v 2 . Then, as every vertex in G ′ apart from v 1 and v 2 has degree 3, it follows that G ′ − E(P ) consists of two isolated vertices (v 1 and v 2 ) and a set S of isolated edges. Thus S is an independent set in L(G ′ ), and so L(G ′ ) is near-bipartite. Now suppose that L(G ′ ) is near-bipartite. Then L(G ′ ) contains a set S of vertices, such that F = L(G ′ ) − S is a forest. As L(G ′ ) is a line graph, L(G ′ ) is claw-free. This means that F is the disjoint union of one or more paths. Suppose that F contains more than one path. Then, as e 1 and e 2 are the only two vertices in L(G ′ ) that are of degree 2 and all other vertices of L(G ′ ) have degree 4, at least one path of F has an end-vertex of degree 4 in L(G ′ ). Let f be this vertex. As f is the end-vertex of a path in F , we find that f has three neighbours f 1 , f 2 , f 3 in S. As S is an independent set, {f, f 1 , f 2 , f 3 } induces a claw in L(G ′ ). This contradiction tells us that F consists of exactly one path P , and by the same reasoning, e 1 and e 2 must be the end-vertices of P .
Hence every vertex of P apart from its end-vertices has two neighbours in S and every vertex in S has four neighbours on P . Moreover, e 1 and e 2 have exactly one neighbour in S. This means that 1 + 1 + 2(|V (P )| − 2) = 4|S|, so |S| = 1 2 (|V (P )| − 1). Hence we find that so |V (P )| = n + 1. Hence, as G ′ has n + 2 vertices, the pre-image of P in G ′ is a Hamilton path of G ′ with end-vertices v 1 and v 2 .
By combining Claims 1 and 2 we have completed our hardness reduction and the theorem is proved. ⊓ ⊔ Theorem 1 has the following immediate consequence (take k = n).
Corollary 1. Independent Feedback Vertex Set is NP-complete for line graphs of planar subcubic bipartite graphs.
We will now prove that Independent Feedback Vertex Set is NP-complete for graphs with no small cycles even if their maximum degree is small. The length of a cycle C is the number of edges of C. The girth g(G) of a graph G is the length of a shortest cycle of G; if G has no cycles then g(G) = ∞. The subdivision of an edge e = uv in a graph deletes e and adds a new vertex w and edges uw and wv. We first need the following observation, which is well known. For completeness we give a short proof.
Lemma 1 (see e.g. [34]). Let uv be an edge in a graph G. Let G ′ be the graph obtained from G after subdividing uv. Then G has a feedback vertex set of size at most k if and only if G ′ does.
Proof. Let w denote the new vertex obtained from subdividing uv. Any feedback vertex set S of G is a feedback vertex set of G ′ . Suppose S ′ is a feedback vertex set of G ′ . If w / ∈ S ′ , then S ′ is a feedback vertex set of G. Suppose w ∈ S ′ . If at least one of u and v are in S ′ as well, then S ′ \ {w} is a feedback vertex set of G. If neither u nor v belong to S ′ , then (S ′ \ {w}) ∪ {u}) is a feedback vertex set of G with the same size as S ′ .
⊓ ⊔ Lemma 1 implies that Feedback Vertex Set is NP-complete for graphs of girth at least g for every constant g ≥ 3. We also use this lemma to prove our next result. Proposition 1. For every constant g ≥ 3, Independent Feedback Vertex Set is NP-complete for graphs of maximum degree at most 4 and girth at least g.
Proof. For a graph G, let G s be the graph obtained from G after subdividing every edge of G; we say that G s is a subdivided copy of G. Let G s be the graph class obtained from a graph class G after replacing each G ∈ G by its subdivided copy G s . It follows from Lemma 1 that if Feedback Vertex Set is NP-complete for some graph class G, then it is also NP-complete for G s . By starting from the fact that Feedback Vertex Set is NP-complete for line graphs of planar cubic bipartite graphs [35] and applying this observation a sufficient number of times, we find that for any constant g ≥ 3, Feedback Vertex Set is NP-complete for graphs of maximum degree at most 4 and girth at least g. Moreover, any non-independent feedback vertex set S of a subdivided copy G s of a graph G contains two adjacent vertices, one of which has degree 2 in G s . Hence, we can remove such a degree 2 vertex from S to obtain a smaller feedback vertex set of G s . Thus all minimum feedback vertex sets of G s are independent. This observation, which can also be found in [34], together with NP-hardness for Feedback Vertex Set for graphs of maximum degree at most 4 and with arbitrarily large girth proves the proposition.

⊓ ⊔
Recall that every line graph is claw-free. We also observe that for a graph H with a cycle C, the class of graphs of girth at least |C| + 1 is a subclass of the class of H-free graphs. Hence, we can combine Corollary 1 and Proposition 1 to obtain the following result.

Corollary 2.
Let H be a graph that contains a claw or a cycle. Then Independent Feedback Vertex Set is NP-complete for H-free graphs of maximum degree at most 4.

Near-Bipartiteness of P 5 -free Graphs
In this section, we show that Near-Bipartiteness is polynomial-time solvable for P 5 -free graphs, i.e. we give a polynomial-time algorithm for testing whether or not a P 5 -free graph has an independent feedback vertex set. To obtain a minimum feedback vertex set we need to first run this algorithm and then do the additional work described in Section 4.
Our algorithm in this section solves a slightly more general problem, which is a special variant of List 3-Colouring. In the List 3-Colouring problem each vertex v is assigned a subset L(v) of colours from {1, 2, 3} and we must verify whether or not a 3-colouring exists in which each vertex v is coloured with a colour from L(v). We say that a 3-colouring of a graph G is semi-acyclic if the vertices coloured 2 or 3 induce a forest, and we note that G has such a colouring if and only if G is nearbipartite. This leads to the following variant of List 3-Colouring.

List Semi-Acyclic 3-Colouring
Instance: a graph G and a function L : , is a yes-instance of List Semi-Acyclic 3-Colouring. To recognise nearbipartite P 5 -free graphs in polynomial time, we will show the stronger statement that List Semi-Acyclic 3-Colouring is polynomial-time solvable for P 5 -free graphs.
A set of vertices in a graph G is dominating if every vertex of G is either in the set or has at least one neighbour in it. We will use a lemma of Bacsó and Tuza.

Lemma 2 ([3]
). Every connected P 5 -free graph admits a dominating set that induces either a clique or a P 3 .
Lemma 2 implies that every connected 3-colourable P 5 -free graph has a dominating set of size at most 3 (since it has no clique on more than three vertices). This was used by Randerath et al. [40] to show that 3-Colouring is polynomial-time solvable on P 5 -free graphs. Their algorithm tries all possible 3-colourings of a dominating set of size at most 3. It then adjusts the lists of the other vertices (which were originally set to {1, 2, 3}) to lists of size at most 2. As shown by Edwards [13], 2-List Colouring can be translated to an instance of 2-Satisfiability, which is well known and readily seen to be solvable in linear time. Hence this approach results in a polynomial (even constant) number of instances of the 2-Satisfiability problem.
Our goal is also to apply Lemma 2 on a connected P 5 -free graph G and to reduce an instance (G, L) of List Semi-Acyclic 3-Colouring to a polynomial number of instances of 2-Satisfiability. However, in our case this is less straightforward than in the case of 3-Colouring restricted to P 5 -free graphs: the restriction of List Semi-Acyclic 3-Colouring to lists of size 2 turns out to be NP-complete for general graphs even if every list consists of either colours 1 and 3 or only colour 2.
Proof. The problem is clearly in NP so we need only show that it is NP-hard. We do this by reduction from Satisfiability.
Let φ be an instance of Satisfiability. Note that we can assume that, for each variable x, φ contains both the literals x and x, and that each clause contains more than one literal (otherwise in polynomial-time we can obtain another smaller instance whose satisfiability is the same as that of φ). We create an instance (G, L) of List Semi-Acyclic 3-Colouring as follows (see also We claim that (G, L) is a yes-instance of List Semi-Acyclic 3-Colouring if and only if φ is a yes-instance of Satisfiability.
The list for each vertex is displayed and literals label the vertices that represent them except that, for each variable x, one vertex is labelled vx.
First suppose that G has a semi-acyclic 3-colouring that respects L, and let us show that a satisfying assignment for φ can be found. For each variable x, if v x is coloured 1, then let x be true; if it is coloured 3, let x be false. Note that every other vertex corresponding to the positive literal x must be coloured the same as x, and every vertex corresponding to an instance of x is coloured differently, so each literal is coloured 1 if and only if it is true. Thus every clause contains a true literal, otherwise in the corresponding cycle every vertex would be coloured 2 or 3 and the colouring would not be semi-acyclic. Now suppose that φ has a satisfying assignment. If a literal is true in this assignment, colour the corresponding vertex 1, otherwise colour it 3. Colour each middle vertex with the colour not used on its neighbours (which must be coloured alike). Clearly this is a 3-colouring, and each cycle corresponding to a clause contains a vertex coloured 1 as it contains a true literal. No other cycle in the graph is coloured with only 2 and 3, as the only edges that do not belong to the cycles representing the clauses each join a vertex coloured 1 to a vertex coloured 3. Thus the colouring is semi-acyclic.
⊓ ⊔ By Theorem 2, to prove that List Semi-Acyclic 3-Colouring is polynomialtime solvable on P 5 -free graphs, we need to refine our analysis and exploit P 5 -freeness beyond the use of Lemma 2. We adapt the approach used by Hoàng et al. [23] to show that k-Colouring is polynomial-time solvable on P 5 -free graphs for all k ≥ 3 (extending the analogous result of Randerath et al. [40] for 3-Colouring). Let us first outline the proof of [23].
The approach of Hoàng et al. [23] to solve k-Colouring for P 5 -free graphs for any integer k uses Lemma 2 as a starting point, just as the approach of Randerath et al. [40] does for the k = 3 case. Lemma 2 implies that every k-colourable P 5 -free graph G has a dominating set D of size at most k (as the clique number of a k-colourable graph is at most k). Fix an ordering D = {v 1 , . . . , v |D| }. Then decompose the set of vertices not in D into |D| "layers" so that the vertices in a layer i are adjacent to v i (and possibly to v j for j > i) but not to any v h with h < i. Using the P 5 -freeness of G to analyse the adjacencies between different layers, it is possible to branch in such a way that a polynomial number of instances of (k − 1)-Colouring are obtained. Hence, by repetition, a polynomial number of instances of 2-Colouring are reached, which can each be solved in polynomial time due to the result of [13].
The algorithm of [23] works by considering the more general List k-Colouring problem, where each vertex v is assigned a list L(v) ⊆ {1, . . . , k} of permitted colours and the question is whether there is a colouring in which each vertex is assigned a colour from its list. The algorithm immediately removes any vertices whose lists have size 1 at any point (and then adjusts the lists of admissible colours of all neighbours of such vertices). We will follow the approach of [23]. In our case k = 3, but we cannot remove any vertices whose lists contain a singleton colour if this colour is 2 or 3. To overcome this extra complication we carefully analyse the 4-vertex cycles in the graph after observing that these cycles are the only obstacles that may prevent a 3-colouring of a P 5 -free graph from being semi-acyclic.
For a subset S ⊆ V (G) of the vertex set of a graph G, we let G[S] denote the subgraph of G induced by S.
Proof. Consider an input (G, L) for the problem such that G is P 5 -free. Since the problem can be solved component-wise, we may assume that G is connected. If G contains a K 4 , then it is not 3-colourable and the input is a no-instance. As we can test whether or not G contains a K 4 in O(n 4 ) time, we now assume that G is K 4 -free. We may also assume that G contains at least three vertices, otherwise the problem can be trivially solved. For We apply the following propagation rules exhaustively, and, later in the proof, every time we branch on possibilities, we assume that these rules are again applied exhaustively immediately afterwards. We must show that these rules are safe. That is, that when they modify the instance they do not affect whether or not it is a yes-instance or a no-instance, and when they return the answer no, this is correct and no semi-acyclic colouring that respects the lists can exist. This is trivial for Rules 1 and 2. We may apply Rule 3 since in any 3-colouring of G every pair of colour classes must induce a bipartite graph. We may apply Rules 4 and 5 since in every solution, every induced C 4 must contain at least one vertex coloured with colour 1. In fact, if there is a 3-colouring of G with a cycle made of vertices coloured only 2 and 3, then this cycle must be an even cycle. Since G is P 5 -free, such a cycle must in fact be isomorphic to C 4 . Hence the problem, when restricted to P 5 -free graphs, is equivalent to testing whether G has a 3-colouring respecting the lists such that every induced C 4 contains at least one vertex coloured with colour 1. By Lemma 2, G has a dominating set S that is either a clique or induces a P 3 . If S is a clique, then it has at most three vertices, as G is K 4 -free, so we can find such a set in O(n 4 ) time. Thus, adding vertices arbitrarily if necessary, we may assume S = {a 1 , a 2 , a 3 }. We consider all possible combinations of colours that can be assigned to the vertices in S, that is, we branch into at most 3 3 cases, in which a 1 , a 2 and a 3 have each received a colour, or equivalently, have had their list of permissible colours reduced to size exactly 1. In each case we proceed as follows.
Assume that L(a 1 ) = {c 1 }, L(a 2 ) = {c 2 } and L(a 3 ) = {c 3 } and again apply the propagation rules above. Partition the vertices of V \ S into three parts V 1 , V 2 , V 3 : let V 1 be the set of neighbours of a 1 in V \ S, let V 2 be the set of neighbours of a 2 in V \ S that are not adjacent to a 1 , and let Fig. 4). Each vertex in V 3 is non-adjacent to a 1 and a 2 , so it is adjacent to a 3 , as S is dominating.
Since for every i ∈ {1, 2, 3}, every vertex of V i belongs to G ci , it follows that V 1 , V 2 and V 3 each induce a bipartite graph in G by Rule 3. Therefore, we may partition each V ′ i into two (possibly empty) independent sets V ′′ i and V ′′′ i . Our strategy is to reduce the instance (G, L) to a polynomial number of instances (G, L ′ ), in which there are no edges between any two distinct sets V ′ i and V ′ j (defined with respect to L ′ ). We will do this by branching on possible partial colourings in such a way that afterwards there are no edges between V ′′ i and V ′′′ j , no edges between V ′′ i and V ′′ j and no edges between V ′′′ i and V ′′′ j for every pair i, j ∈ {1, 2, 3} with i = j. As the branching procedure is similar for each of these possible combinations, we pick an arbitrary pair, namely V ′′ 1 and V ′′ 2 . As we shall see, we do not remove any edges between V ′′ 1 and V ′′ 2 . Instead, we decrease the lists of some of their vertices to size 1, so that these vertices will leave contains an induced 2P 2 (see Fig. 5) with edges uu ′ and vv ′ for u, v ∈ V ′′ 1 and is a 2P 2 -free bipartite graph, that is, the edges between V ′′ 1 and V ′′ 2 form a chain graph, which means that the vertices of V ′′ 1 can be linearly ordered by inclusion of neighbourhood in V ′′ 2 . In other words, we fix an ordering V ′′ 1 = {u 1 , . . . , u k } such that N V ′′ 2 (u 1 ) ⊇ · · · ⊇ N V ′′ 2 (u k ). We choose an arbitrary colour c ′ ∈ {1, 2, 3} \ {c 1 , c 2 }. Note that if c 1 = c 2 then this choice is unique and otherwise there are two choices (as we will show, it suffices to branch on only one choice). Also note that every vertex in V ′′ 1 and V ′′ 2 has colour c ′ in its list.
We now branch over k +1 possibilities, namely the possibilities that vertex u i is the first vertex coloured with colour c ′ (so vertices u 1 , . . . , u i−1 , if they exist, do not get colour c ′ ) and the remaining possibility that no vertex of V ′′ 1 is coloured with colour c ′ . To be more precise, for branch i = 1 we set L(u 1 ) = {c ′ }, for each branch 2 ≤ i ≤ k we remove colour c ′ from each of L(u 1 ), . . . , L(u i−1 ) and set L(u i ) = {c ′ } and for branch i = k + 1 we remove colour c ′ from each of L(u 1 ), . . . , L(u k ). If i = k + 1, all vertices of V ′′ 1 will have a unique colour in their list and thus leave V ′ 1 and thus V ′′ 1 by definition of V ′ 1 . Hence, V ′′ 1 becomes empty and thus, as required, we no longer have edges between V ′′ 1 and V ′′ 2 . Otherwise, if i ≤ k, then all of u 1 , . . . , u i will have a list containing exactly one colour, so they will leave V ′ 1 and therefore V ′′ 1 . By Rule 1 all neighbours of u i in V ′′ 2 will have c ′ removed from their lists, so they will leave V ′ 2 and therefore V ′′ 2 . By the ordering of neighbourhoods of vertices in V ′′ 1 , this means that no vertex remaining in V ′′ 1 has a neighbour remaining in V ′′ 2 , so if i ≤ k, then it is also the case that we no longer have edges between V ′′ 1 and V ′′ 2 . Note that removing all the edges between distinct sets V ′ i and V ′ j in the above way involves branching into O(n 12 ) cases. We consider each case separately, and for each case we proceed as below.
By the above branching we may assume that there are no edges between any two distinct sets V ′ i and V ′ j . We say that an induced C 4 is tricky if there exists a (proper) colouring of it (not necessarily extendable to all of G) using only the colours 2 and 3 such that every vertex receives a colour from its list. We say that a vertex in an induced C 4 is good for this induced C 4 if its list contains the colour 1. By definition of tricky, every good vertex for a tricky induced C 4 must belong to V ′ 1 ∪ V ′ 2 ∪ V ′ 3 . By Rules 4 and 5, every tricky induced C 4 must contain at least two good vertices. If an induced C 4 contains two good vertices that are adjacent, then they must belong to the same set V ′ i (since there are no edges between any two distinct sets V ′ i and V ′ j ), so they must have the same list. This means that in every colouring of this induced C 4 that respects the lists, one of the good vertices in this induced C 4 will be coloured with colour 1, contradicting the definition of tricky. We conclude that every tricky induced C 4 must contain exactly two good vertices, which must be non-adjacent.
Suppose G contains a tricky induced C 4 on vertices v 1 , v 2 , v 3 , v 4 , in that order, such that v 1 and v 3 are good. Since the C 4 is tricky, we must either have: Since v 2 and v 4 are not good, and there are no edges between distinct sets of the form V ′ i , the above implies that one of the following must hold: We say that an induced C 4 is strongly tricky if its vertices have lists of this form (see also Fig. 6). Note that, by the above arguments, we may assume that all tricky induced C 4 s in the instances we consider are in fact strongly tricky.  Recall that every tricky induced C 4 is strongly tricky, and is therefore entirely contained in either G[L 2 ∪ L 1,3 ] or G[L 3 ∪ L 1,2 ]. By Rule 3, G 1 and therefore G[L 2,3 ] is bipartite. Hence we can colour the vertices of L 2,3 with colours from their lists such that no vertex in L 2,3 is adjacent to a vertex of the same colour in G and no induced C 4 s are coloured with colours alternating between 2 and 3 (indeed, recall that induced C 4 s cannot exist in G(L 2,3 ) by Rule 4). It therefore remains to check whether the vertices of G[L 2 ∪ L 1,3 ] (and G[L 3 ∪ L 1,2 ]) can be coloured with colours from their lists so that no pair of adjacent vertices in L 1,3 (resp. L 1,2 ) receive the same colour and every strongly tricky C 4 has at least one vertex coloured 1. By symmetry, it is sufficient to show how to solve the G[L 2 ∪ L 1,3 ] case. Hence we have reduced the original instance (G, L) to a polynomial number of instances of a new problem, which we define below after first defining the instances.
, 3}, such that L 2 is an independent set and L 1,3 induces a bipartite graph.
In particular, for each of our created instances the set L 2 is independent due to Rule 1 and L 1,3 induces a bipartite graph by Rule 3. Note that by definition of troublesome, all tricky induced C 4 s in a troublesome graph are strongly tricky.
Definition 2. Let G be a troublesome graph. A 3-colouring of the graph G is troublefree if each vertex receives a colour from its list, no two adjacent vertices of G are coloured alike and at least one vertex of every strongly tricky induced C 4 of G receives colour 1.
This leads to the following problem.

Trouble-Free Colouring
Instance: a troublesome P 5 -free graph G Question: does G have a trouble-free colouring?
We can encode an instance of Trouble-Free Colouring as an instance of 2-Satisfiability as follows. For each vertex u ∈ L 1,3 , we create two variables u 1 and u 3 . If we assign u 1 or u 3 to be true, this means that u will be assigned colour 1 or 3, respectively. Hence, we need to add the clauses (u 1 ∨ u 3 ) and (u 1 ∨ u 3 ). To ensure that two adjacent vertices are not coloured alike, for each pair of adjacent vertices u, v ∈ L 1,3 we add the clauses (u 1 ∨ v 1 ) and (u 3 ∨ v 3 ). For each strongly tricky C 4 with good vertices u and v, we add the clause (u 1 ∨ v 1 ) to ensure that at least one of them will be assigned colour 1. Let I be the resulting instance of 2-Satisfiability. We claim that G has a trouble-free colouring if and only if I is satisfiable. First suppose that G has a trouble-free colouring. Then setting x c to be true if the vertex x receives colour c gives a satisfying assignment for I. Now suppose that I has a satisfying assignment. Then we colour the vertex v ∈ L 1,3 with colour c if v c is set to true in this assignment. For v ∈ L 2 we colour v with colour 2. No two adjacent vertices of L 1,3 are assigned the same colour, because I is satisfied. No vertex of L 2 is assigned the same colour as one of its neighbours, since L 2 is an independent set and every vertex of L 1,3 is assigned colour 1 or 3. Therefore the obtained colouring is a 3-colouring of G. Since I is satisfied, every strongly tricky C 4 contains at least one vertex coloured 1. Hence G has a trouble-free colouring.
So, by branching, we have reduced the original instance (G, L) of List Semi-Acyclic 3-Colouring to a polynomial number of instances of 2-Satisfiability. If we find that one of the instances of the latter problem is a yes-instance, then we obtain a corresponding yes-instance of Trouble-Free Colouring. We therefore solve Trouble-Free Colouring on G[L 2 ∪L 1,3 ] and (after swapping colours 2 and 3) on G[L 3 ∪L 1,2 ]. If one of these two instances of Trouble-Free Colouring is a no-instance, then we return no for this branch and try the next one. If both of these are yes-instances, then we return yes and obtain a semi-acyclic 3-colouring by combining the colourings on We first branch up to 3 3 times and then sub-branch O(n 12 ) times and in each case we apply the rules. It is readily seen that every created instance of 2-Satisfiability is solvable in O(n 2 ) time (see also Edwards [13]). This leads to a total runtime of O(n 4 ) + O(1) × O(n 12 ) × (O(n 4 ) + O(n 2 )) = O(n 16 ).
⊓ ⊔ As mentioned, Theorem 3 has the following consequence.

Independent Feedback Vertex Sets of P 5 -free Graphs
In this section we prove that Independent Feedback Vertex Set is polynomialtime solvable for P 5 -free graphs by extending the algorithm from Section 3: the first part of our proof uses the proof of Theorem 3, as we will explain in the proof of Proof. Let G be a near-bipartite P 5 -free graph, that is, we assume that G has an independent feedback vertex set. We may assume that G is connected, otherwise, we solve the problem component-wise. We set L(v) = {1, 2, 3} for all v ∈ V (G) and run the algorithm of Theorem 3. As can be seen from the proof of Theorem 3, this algorithm branches up to 3 3 times and then sub-branches O(n 12 ) times. Each branch gives us, after some preprocessing in O(n 4 ) time, either a no answer, in which case we discard this branch, or two vertex-disjoint instances of Trouble-Free Colouring (one on G[L 2 ∪ L 1,3 ] and one (after swapping colours 2 and 3) on G[L 3 ∪ L 1,2 ] and we will denote these two instances by G ′ and G ′′ , respectively. Such instances consist of a troublesome graph G ′ or G ′′ , which is an induced subgraph of G and whose vertices have lists of admissible colours determined by the branching. As explained in the proof of Theorem 3, in any branch that we did not discard, G[L 1 ∪ L 2,3 ] will have a semi-acyclic 3-colouring that respects the lists and L 1 will be the set of vertices that are coloured 1 in any such colouring. Therefore, given troublefree colourings c and c ′ of G ′ and G ′′ , respectively, we can obtain an independent feedback vertex set S(c, c ′ , G ′ , G ′′ ) by taking the union of the set L 1 of G[L 1 ∪ L 2,3 ] and the sets of vertices in G ′ and G ′′ that c or c ′ colour with colour 1. Now let c * and c * * be such that t(G ′ ) = t c * (G ′ ) and t(G ′′ ) = t c * * (G ′′ ). If we know t(G ′ ) and t(G ′′ ), we can compute the size s(G ′ , G ′′ ) = |S(c * , c * * , G ′ , G ′′ )| in O(1) time (and the corresponding independent feedback vertex set S(c * , c * * , G ′ , G ′′ ) in O(n) time). Letŝ be the minimum s(G ′ , G ′′ ) over all branches of our procedure. As our procedure had O(n 12 ) branches, given the values of t(G ′ ) and t(G ′′ ) for every branch, we can computeŝ in O(n 12 ) time. As we branched in every possible way,ŝ is the size of a minimum independent feedback vertex set of G.

⊓ ⊔
We still need a polynomial-time algorithm that computes t(G) for a given troublesome P 5 -free graph. We present such an algorithm in the following lemma (in the proof of this lemma we again use Definitions 1 and 2). Proof. Let G = (V, E) be a troublesome P 5 -free graph. Note that in G, an induced C 4 We construct an auxiliary graph H as follows. We let V (H) = L 1,3 . Every edge of G[L 1,3 ] belongs to H. We say that such edges are red. For non-adjacent vertices v 1 , v 3 ∈ L 1,3 , if there is a strongly tricky induced C 4 on vertices v 1 , v 2 , v 3 , v 4 with v 2 , v 4 ∈ L 2 , we add the edge v 1 v 3 to H. We say that such edges are blue. Note that H is a supergraph of G[L 1,3 ] and that there exists at most one edge, which is either blue or red, between any two vertices of H.
We say that a colouring of H feasible if the following two conditions are met: (i) no red edge is monochromatic, that is, the two end-vertices of every red edge must be coloured, respectively, 1&3 or 3&1; (ii) the two end-vertices of every blue edge must be coloured, respectively, 1&3, 3&1 or 1&1 (the only forbidden combination is 3&3, as in this case we obtain a strongly tricky induced C 4 in G with colours 2 and 3).
We note that there is a one-to-one correspondence between the set of trouble-free colourings of G and the set of feasible colourings of H. Hence, we need to find a feasible colouring of H that minimises the number of vertices coloured 1. Let R 1 , . . . , R p be the components of G[L 1,3 ], or equivalently, of the graph obtained from H after removing all blue edges. We say that these are red components. As G[L 1,3 ] is bipartite and P 5 -free, all red components of H are bipartite and P 5 -free. We denote the bipartition classes of each R i by X i and Y i , arbitrarily (note that these classes are unique, up to swapping their order). We apply the following rules on H exhaustively, making sure to only apply a rule if all previous rules have been applied exhaustively.

Rule 1.
If there is a blue edge in H between two vertices u, v ∈ X i or two vertices u, v ∈ Y i , then assign colour 1 to u and v. Rule 2. If there is a blue edge e in H between a vertex u ∈ X i and a vertex v ∈ Y i , then delete e from H. Rule 3. If there are blue edges uv and uv ′ where u ∈ X i ∪ Y i , v ∈ X j and v ′ ∈ Y j (j = i), then assign colour 1 to u. Rule 4. If an uncoloured vertex u is adjacent to a vertex with colour 3 via a blue edge, then assign colour 1 to u. Rule 5. If an uncoloured vertex u is adjacent to a coloured vertex v via a red edge, then assign colour 1 to u if v has colour 3 and assign colour 3 to u otherwise. Rule 6. If there is a red edge with end-vertices both coloured 1 or both coloured 3, or a blue edge with end-vertices both coloured 3, then return no. Rule 7. Remove all vertices that have received colour 1 or colour 3, keeping track of the number of vertices coloured 1.
Since each R i is connected and bipartite, in every feasible colouring of H, for all i either all vertices in the set X i must be coloured 1 and all vertices in the set Y i must be coloured 3, or vice versa. Therefore we may safely apply Rules 1 and 2. Suppose that a vertex u ∈ V (H) is incident with two blue edges uv and uv ′ in H for two vertices v and v ′ that belong to different partition classes of the same red component.
Then, as either v or v ′ must get colour 3 in every feasible colouring of H, we find that u must receive colour 1. Hence Rule 3 is also safe to apply. Rules 4-6 are also safe; this follows immediately from the definition of a feasible colouring. If a vertex v is assigned colour 3, then by Rule 4 all its neighbours along blue edges get colour 1, so Property (ii) of a feasible colouring is satisfied for all blue edges with end-vertex v.
If a vertex v is assigned a colour, then by Rule 5 all its neighbours along red edges get a different colour, so Property (i) of a feasible colouring is satisfied. We conclude that Rule 7 is safe. By Rules 1 and 2, if two vertices are in the same red component R i , we may assume that they are not connected by a blue edge. Hence, we may assume from now on that red components contain no blue edges in H. By Rule 3, we may also assume that no vertex in V (H) \ V (R j ) is joined via blue edges to both a vertex in X j and a vertex in Y j .
From H we construct another auxiliary graph H * as follows. First, we replace each red component R i on more than two vertices by an edge x i y i , which we say is a red edge. Hence, the set of red components of H is reduced to a set of red components in H * in such a way that each red component of H * is either an edge or a single vertex. Next, for i = j we add an edge, which we say is a blue edge, between two vertices x i and x j if and only if there is a blue edge between a vertex in X i and a vertex in X j . Similarly, for i = j we add a blue edge, between two vertices y i and x j (resp. y j ) if and only if there is a blue edge between a vertex in Y i and a vertex in X j (resp. Y j ).
Recall that, by Rules 1 and 2, no two vertices in the same component R i are connected by a blue edge in H. So every feasible colouring of H corresponds to a feasible colouring of H * and vice versa. To keep track of the number of vertices coloured 1, we introduce a weight function w : V (H * ) → Z + by setting w(x i ) = |X i | and w(y i ) = |Y i |.
Our new goal is to find a feasible colouring c of H * that minimises the sum of the weights of the vertices coloured 1, which we denote by w(c).
Since for each i no vertex in V (H) \ V (R i ) is joined via blue edges to both a vertex in X i and a vertex in Y i , we find that H * contains no triangle consisting of one red edge and two blue edges. As red edges induce a disjoint union of isolated edges, this means that the only triangles in H * consist of only blue edges. Let B 1 , . . . , B q be the components of the graph obtained from H * after removing all red edges. We say that these are blue components (this includes the case where they are singletons).
We will now show that all blue components of H * are complete.

Claim 1. Each B i is a complete graph.
We prove Claim 1 as follows. For contradiction, suppose there is a blue component B i that is not a complete graph. Then B i contains three vertices u, v, w such that uv and vw are blue edges and uw is not a blue edge. As uv and vw are blue edges, v is not in the same red component of H * as u or w. As no triangle in H * can have two blue edges and one red edge, u and w are not adjacent in H * , meaning that u, v, w in fact belong to three different red components in H. Let u ′ v ′ and v ′′ w ′ be blue edges of H corresponding to the edges uv and vw, respectively. As uw is not a blue edge in H * , we find that u ′ w ′ is not a blue edge in H ′ . We distinguish between two cases and show that neither of them is possible.
As u ′ v ′ is a blue edge in H, we find that in G, the vertices u ′ and v ′ must have at least two common neighbours in L 2 . For the same reason, in G, the vertices v ′ and w ′ must have at least two common neighbours in L 2 . Since u ′ w ′ is not a blue edge in H, we find that in G, the vertices u ′ and w ′ have at most one common neighbour in L 2 . Therefore G contains two vertices p, q ∈ L 2 such that p is adjacent to u ′ and v ′ but non-adjacent to w ′ and q is adjacent to v ′ and w ′ but non-adjacent to u ′ . As L 2 is an independent set in G, p is non-adjacent to q. Now G[{u ′ , p, v ′ , q, w ′ }] is a P 5 , which is a contradiction.
Let R i be the red component of H containing v ′ and v ′′ . Then, due to the way the red edges of H * are constructed, either v ′ and v ′′ both belong to X i , or they both belong to Y i . As R i is bipartite, connected and P 5 -free, R i must contain a vertex s that is adjacent to both v ′ and v ′′ . Just as in Case 1, in G the vertices u ′ and v ′ have at least two common neighbours p, p ′ ∈ L 2 , and v ′ and w ′ also have at least two common neighbours q, q ′ ∈ L 2 . As L 2 is independent in G, it follows that {p, p ′ , q, q ′ } is also an independent set (which may have size smaller than 4). Now p must be adjacent to at least one vertex in {s, v ′′ }, as otherwise G[{u ′ , p, v ′ , s, v ′′ }] would be a P 5 . Similarly, p ′ must be adjacent to at least one vertex in {s, v ′′ }. If p and p ′ are both adjacent to s, then there is a blue edge between u ′ and s in H. This is not possible, as then we would have applied Rule 3. If p and p ′ are both adjacent to v ′′ then there is a blue edge between u ′ and v ′′ in H, so Case 1 applies and we are done. We may therefore assume that p is adjacent to s but non-adjacent to v ′′ , and that p ′ is adjacent to v ′′ but non-adjacent to s. Similarly, we may assume that q is adjacent to s but non-adjacent to v ′ , and that q ′ is adjacent to v ′ , but non-adjacent to s. As p, p ′ , q have different neighbourhoods in {s, v ′′ }, we find that p, p ′ , q are pairwise distinct. Recalling that {p, p ′ , q} ⊆ L 2 is an independent set, it follows that G[{p, v ′ , p ′ , v ′′ , q}] is a P 5 . This contradiction completes Case 2. Hence we have proven Claim 1.
By Claim 1, H * is the disjoint union of several blue complete graphs with red edges between them. Recall that we allow the case where these blue complete graphs contain only one vertex. On H * we apply the following rule exhaustively in combination with Rules 4-7. While doing this we keep track of the weights of the vertices coloured 1.

Rule 8.
If there exist (red) edges u 1 v 1 and u 2 v 2 for u 1 , u 2 ∈ B i and v 1 , v 2 ∈ B j (i = j), then assign colour 1 to every vertex in ( Since Rules 4 and 5 can be safely applied on H, they can be safely applied on H * . It follows that Rules 6 and 7 can also be safely applied on H * . We may also safely apply Rule 8: the red edges u 1 v 1 and u 2 v 2 force u i and v i to have different colours for i ∈ {1, 2}, whereas the blue components forbid u 1 , u 2 both being coloured 3 and v 1 , v 2 both being coloured 3. Hence, exactly one of u 1 , u 2 and exactly one of v 1 , v 2 must be coloured 3. Because at most one vertex in any blue component may be coloured 3, this implies that all vertices in (B i ∪ B j ) \ {u 1 , u 2 , v 1 , v 2 } must be coloured 1.
As every vertex is incident with at most one red edge in H * , we obtain a resulting graph that is an induced subgraph of H * with the following property: if there exist (red) edges u 1 v 1 and u 2 v 2 for u 1 , u 2 ∈ B i and v 1 , v 2 ∈ B j , then {u 1 , u 2 , v 1 , v 2 } induces a connected component of H * . We can colour such a 4-vertex component in exactly two ways and we remember the colouring with minimum weight (either w(u 1 ) + w(v 2 ) or w(u 2 ) + w(v 1 ) depending on whether u 1 gets colour 1 or 3, respectively). Hence, from now on we may assume that the resulting graph, which we again denote by H * , does not have such components. That is, there is at most one red edge between any two blue components of H * . As we can colour H * component-wise, we may assume without loss of generality that H * is connected.
For each B i we define the subset B ′ i to consist of those vertices of B i not incident with a red edge, and we let B ′′ i = B i \ B ′ i . We note the following. If we colour every vertex of some B ′′ i with colour 1, then every neighbour of every vertex of B ′′ i in any other blue component B j must be coloured 3 by Rule 5 (recall that vertices in different blue components are connected to each other only via red edges). As soon as one vertex u in some blue component B j has colour 3, all other vertices in B j − u must get colour 1 by Rule 4. In this way we can use Rule 4 and 5 exhaustively to propagate the colouring to other vertices of H * where we have no choice over what colour to use.
Recall that no vertex of H * is incident with more than one red edge. This is a crucial fact: it implies that propagation to other blue components of H * happens only via red edges vw between two blue components, one end-vertex of which, say v, is first coloured 1, which implies that the other end-vertex w of such an edge must get colour 3; this in turn implies that all other vertices in the blue component containing w must get colour 1 and so on. Hence, as H * was assumed to be connected, colouring every vertex of a set B ′′ i with colour 1 propagates to all vertices of H * except for the vertices of B ′ i . Note that we may still colour (at most) one vertex of B ′ i with colour 3. Due to the above, we now do as follows for each i ∈ {1, . . . , q} in turn: We colour every vertex of B ′′ i with colour 1 and propagate to all vertices of H * except for the vertices of B ′ i . If we obtain a monochromatic red edge or a blue edge whose end-vertices are coloured 3, we discard this option (by Rule 6). Otherwise, we assign colour 3 to a vertex u ∈ B ′ i with maximum weight w(u) over all vertices in We store the resulting colouring c i that corresponds to this option.
After doing the above for all q options, it remains to consider the cases where every B ′′ i contains (exactly) one vertex coloured 3. Before we can use another propagation argument that tells us which vertices get colour 3, we first perform the following steps, only applying a step when the previous ones have been applied exhaustively. These steps follow immediately from the assumption that every B ′′ i contains a vertex coloured 3. If due to (ii) we obtain a monochromatic red edge or a blue edge whose end-vertices are coloured 3, we discard this option (using Rule 6). Otherwise, we may assume from now on that B ′ i = ∅, so B ′′ i = B i due to (i) and that |B i | ≥ 2 due to (ii). Note that doing (iii) does not disconnect the graph: the vertices in the vertices in B ′ i that are coloured in (i) only have neighbours in the clique B i (and these are via blue edges) and if a vertex of v ∈ B ′′ i is coloured with colour 3 in (ii), then its only neighbour w (via a red edge) is in a set B ′′ j and since (i) has been applied exhaustively, the only other neighbours of w are in B ′′ j (via blue edges), so the propagation stops there and the graph does not become disconnected.
By our procedure, every vertex of every blue component B i is incident with a red edge, so the total number of outgoing red edges for each B i is equal to |B i | ≥ 2, and all outgoing red edges go to |B i | different blue components. Hence the graph H ′ obtained from H * by contracting each blue component to a single vertex has minimum degree at least 2. As H ′ has minimum degree at least 2, we find that H ′ contains an edge that is not a bridge (a bridge in a connected graph is an edge whose removal disconnects the graph). Let uv be the corresponding red edge in H * , say u belongs to B i and v belongs to B j .
We have two options to colour u and v, namely by 1, 3 or 3, 1. We try them both. Suppose we first give colour 1 to u. Then we propagate in the same way as before. Because uv is not a bridge in H ′ , eventually we propagate back to B i by giving colour 3 to an uncoloured vertex of B i . When that happens we have "identified" the colour-3 vertex of B i and then need to colour all other vertices of B i with colour 1. This means that we can in fact propagate to all blue components of H * , just as before.
If at some point we obtain a monochromatic red edge or a blue edge with end-vertices coloured 3, then we discard this option (by Rule 6). Next, we give colour 1 to v and proceed similarly.
At the end we have at most q + 2 different feasible colourings of H * . We pick the one with minimum weight and translate the colouring to a feasible colouring of H. Finally, we translate the feasible colouring of H to a trouble-free colouring of the original graph G.
It remains to analyse the runtime. Let n be the number of vertices in G. Given two non-adjacent vertices in L 1,3 , we can test whether they have have two common neighbours in L 2 in O(n) time. Therefore we can construct H in O(n 3 ) time.
Applying  Proof. Let G be a P 5 -free graph on n vertices. As we can check in O(n 16 ) time whether or not G is near-bipartite, we may assume without loss of generality that G is nearbipartite. By Lemma 3, in O(n 16 ) time we can reduce this problem to solving O(n 12 ) instances of Trouble-Free Colouring on induced subgraphs of G. By Lemma 4, we can solve each of these instances in O(n 3 ) time. The result follows. ⊓ ⊔ Remark 1. From our proof, we can find in polynomial time not just the size of a minimum independent feedback vertex set, but also the set itself. The corresponding algorithm can also be adapted to find in polynomial time a maximum independent feedback vertex of a P 5 -free graph, or an independent feedback vertex set of arbitrary fixed size (if one exists).

Independent Odd Cycle Transversal
Recall that an (independent) set S ⊆ V of a graph G is an (independent) odd cycle transversal if G − S is bipartite. We also recall that a graph G has an independent odd cycle transversal if and only if G is 3-colourable. This means that if 3-Colouring is NP-complete for a graph class G, then so is Independent Odd Cycle Transversal. Hence, as 3-Colouring is NP-complete for graphs of girth at least g for any constant g ≥ 3 [14] (see also [27,31]) and for line graphs [24], we find the following result.

Proposition 2. Independent Odd Cycle Transversal is NP-complete for
graphs of girth at least g for any constant g ≥ 3; -for line graphs.
As shown by Chiarelli et al. [12], Odd Cycle Transversal is also NP-complete for graphs of girth at least g for any constant g ≥ 3 and for line graphs. Hence, both problems are NP-complete for H-free graphs if H contains a cycle or a claw.
Our algorithm for Independent Feedback Vertex Set restricted to P 5 -free graphs can also be used to show that Independent Odd Cycle Transversal is polynomial-time solvable for P 5 -free graphs. We just have to replace those steps from the algorithm that check whether the vertices minus the independent set (that is, the vertices coloured 2 and 3) induce a forest by steps that check whether these vertices form a bipartite graph.

Conclusions
Our main result is that Independent Feedback Vertex Set is polynomial-time solvable for P 5 -free graphs. As explained in Section 5, our algorithm can be readily adapted to also solve Independent Odd Cycle Transversal for P 5 -free graphs in polynomial time. We also proved that Independent Feedback Vertex Set is NP-complete for H-free graphs if H contains a cycle or a claw. As discussed, the same hardness results were known for Feedback Vertex Set and 3-Colouring, and the hardness results for 3-Colouring immediately transfer across to Independent Odd Cycle Transversal.
Another problem that is closely related to 3-Colouring is Independent Vertex Cover, which is the independent problem variant of Vertex Cover. The latter problem is that of testing whether or not a given graph G has a set S of size at most k for some given integer k, such that the vertices of G − S form an independent set. Similarly, the Independent Vertex Cover problem requires S to be an independent set and is equivalent to asking whether or not a graph has a 2-colouring such that one colour class has size at most k. This problem is clearly solvable in polynomial time. In contrast, Vertex Cover is NP-complete for graphs of girth at least g for any constant g ≥ 3 [37], but Vertex Cover stays polynomial-time solvable for claw-free graphs [33,41].
Apart from Independent Vertex Cover, the complexities of the other problems that we discussed are not settled for H-free graphs when H is a linear forest (disjoint union of one or more paths), or even when H is a path. Randerath and Schiermeyer [38] proved that 3-Colouring is polynomial-time solvable for P r -free graphs for r = 6, and more recently, Bonomo et al. [6] proved this for r = 7. The complexity of 3-Colouring for P r -free graphs is not known for r ≥ 8 (we refer to [19] for further details on k-Colouring for P r -free graphs).
The problems Feedback Vertex Set and Odd Cycle Transversal are polynomial-time solvable for the class of permutation graphs [8], which contains the class of P 4 -free graphs [8], but their complexity is not known for P r -free graphs when r ≥ 5. This is in contrast to Independent Feedback Vertex Set and Independent Odd Cycle Transversal due to our result on P 5 -free graphs. For these two problems we do not know their complexity for r ≥ 6. As mentioned, Lokshantov et al. [29] proved that Vertex Cover (or equivalently, Independent Set) is polynomial-time solvable for P 5 -free graphs, and this result was recently extended to P 6 -free graphs by Grzesik et al. [21]. The computational complexity of Vertex Cover for P r -free graphs is not known for r ≥ 7.
We refer to Table 1 for a summary of the above problems. In this table we also added the Dominating Induced Matching problem, which is also known as the Efficient Edge Domination problem. This problem is that of deciding whether or not a graph G has an independent set S such that G − S is an induced matching, that is, the disjoint union of a set of isolated edges. Cardoso et al. [11] proved that G − S is in fact a maximum induced matching. We note that every graph G whose vertex set allows a partition into an independent set and an induced matching is 3colourable. Grinstead et al. [20] proved that Dominating Induced Matching is NP-complete. Later, the problem was shown to be NP-complete or polynomial-time solvable for various graph classes. In particular, Brandstädt and Mosca [9] proved that Dominating Induced Matching for P r -free graphs is polynomial-time solvable if r = 7. Later they extended their result to r = 8 [10]. The complexity status of Dominating Induced Matching is unknown for r ≥ 9. Hertz et al. [22] conjectured that the problem is polynomial-time solvable for H-free graphs whenever H is a forest, each connected component is a subdivided claw, a path or an isolated vertex.
Completing Table 1 is a highly non-trivial task. In particular, we note that no NPhardness results are known for any of the problems in Table 1 when restricted to P r -free graphs. As such, it would be interesting to know whether the problem of determining whether or not a P r -free graph has an independent feedback vertex set (or equivalently, whether or not a P r -free graph is near-bipartite) is polynomially equivalent to the 3-Colouring problem restricted to P f (r) -free graphs for some function f .
To solve Independent Feedback Vertex on P r -free graphs for r ∈ {6, 7, 8}, one could try to exploit the techniques used to solve 3-Colouring for P r -free graphs, just as we did for the r = 5 case in this paper. However, this seems difficult due to additional complications and a different approach may be required. r ≤ 4 r = 5 r = 6 r = 7 r = 8 r ≥ 9 3-Colouring P P [40]  Finally, we point out that the connected problem variants Connected Feedback Vertex Set, Connected Odd Cycle Transversal, and Connected Vertex Cover, which each require the desired set S of size at most k to induce a connected graph, are also known to be NP-complete for line graphs and graphs of arbitrarily large girth. This was shown by Chiarelli et al. [12] for Connected Feedback Vertex Set and Connected Odd Cycle Transversal, whereas Munaro [36] proved that Connected Vertex Cover is NP-hard for line graphs (of planar cubic bipartite graphs) and for graphs of arbitrarily large girth. Moreover, for these three problems the complexity has not yet been settled for H-free graphs when H is a linear forest (see [12] for some partial results in this direction).