1 Introduction
Many interesting classes of graphs are defined by forbidding induced subgraphs, see [1] for a survey. This is why the detection of several kinds of induced subgraphs is interesting, see [5] where many such problems are surveyed. In particular, the problem of deciding whether a graph contains as an induced subgraph some graph obtained after possibly subdividing prescribed edges of a prescribed graph has been studied. It turned out that this problem can be polynomial or NPcomplete according to and to the set of edges that can be subdivided. The most general tool for solving this kind of problems (when they are polynomial) seems to be the threeinatree algorithm of Chudnovsky and Seymour:
Theorem 1.1 (see [2])
Let be a graph and be three distinct vertices of . Deciding whether there exists an induced tree of that contains can be performed in time .
How to use threeinatree is discussed in [2] and further evidences of its generality are given in [5]. The complexity of fourinatree is not known, and more generally of inatree, where is a fixed integer. But these problems are more tractable when restrictions are given on the girth (length of a smallest cycle) of the graph as suggested by Derhy, Picouleau and Trotignon who proved:
Theorem 1.2 (see [3])
Let be a trianglefree graph and be four distinct vertices of . Deciding whether there exists an induced tree of that contains can be performed in time .
Here, we study inatree for graphs of girth at least . Note that the problem is solved by the two theorems above for and . For , we follow the method that has been already succesful for Theorems 1.1 and 1.2: studying the structure of a graph that does not contain the desired tree. It turns out that in most of the cases, the structure is simple. Note that the proofs in the present work are independent form [2, 3]: we do not use results from [2, 3], and as far as we can see, our results do not simplify [2] or [3].
We call structure any graph obtained from the cycle on vertices by adding a pending path to each vertex of cycle, see Section 4 for a formal definition. An example is shown in Figure 1 which obviously does not contain an induced tree covering the pending vertices. The main result of Section 2 states that for , a graph of girth at least that does not contain an induced tree covering given vertices must contain a structure. The main result of Section 4 states that (with one exception, see below), if the graph contains a structure, then the structure decomposes the graph, meaning that every vertex of the original cycle is a cutvertex of the graph.
But there is a noteworthy exception that arises curiously only when . The graph on Figure 2 is obtained from by subdividing all edges once, and by adding a pending path to each vertex of degree 2. This graph has girth 6. Let be a connected induced subgraph of that contains the 6 pending vertices. We claim that contains at least three vertices of degree 3 in . Otherwise, it does not contains at least 2 of them, so the pending vertex whose neighbor is between these is isolated; a contradiction. Hence, contains three vertices of degree 3 and a cycle of length 6 goes through them. Hence, no induced tree of can cover the 6 pending vertices. This is what we call a structure. The main result of Section 3 states roughly that if a graph of girth 6 contains a structure and if no induced tree covers the 6 pending vertices then the structure decomposes the graph, meaning that every pair of vertices of the original and every vertex of degree 2 arising from the subdivisions is a cutset of the graph.
Let us sum up the results. Our main result, Theorem 5.1, states that when , and is a connected graph of girth at least together with vertices then either contains a structure that decomposes , or and contains a structure that decomposes , or contains an induced tree covering the vertices. All this leads to an time algorithm that decides whether a graph of girth at least contains an induced tree that covers prescribed vertices.
Notation, convention, remarks
We use standard notation from [4]. Since we use only induced subgraphs, we say that contains when is an induced subgraph of . Also, by tree of we mean induced subgraph of that is a tree. By path we mean induced path. In complexity of algorithms, stands for the number of vertices of the input graph and for the number of its edges. We call terminal of a graph any vertex of degree one. Solving verticesinatree or terminalsinatree are equivalent problems, because if vertices of graph are given, we build the graph obtained from by adding a pending neighbor to , . An induced tree of covers if and only an induced tree of covers . Hence, in the rest of the paper we assume for convenience that the vertices to be covered are all terminals.
2 Linking a vertex to a tree
Recall that a terminal in a graph is a vertex of degree 1. A branchvertex is a vertex of degree at least 3. The following is a basic fact whose proof is omited.
Lemma 2.1
A tree with terminals contains at most branchvertices. Moreover if contains exactly branchvertices then every branchvertex is of degree 3.
Lemma 2.2
Let be integers such that and . Let be a graph of girth at least and be distinct terminals of . Let be an induced tree of whose terminals are . Let be a path from to such that has at least one neighbor in and no vertex of has neighbors in . Then one and only one of the following outcomes holds:

contains a tree of that covers .

. Moreover, and can be described as follows (up to a relabelling of ):

is the union of vertexdisjoint paths , , …, ;

the only edges between these paths are such that is a path;

.

This is algorithmic in the sense that when and are given, the tree of the first outcome or the relabelling of the second can be computed in time .
Proof.
Clearly, at most one of the outcomes holds (because if the second holds then no tree of can cover ). Let us prove that at least one of the outcomes holds.
Let be the set of the neighbors of in . If then is a tree that covers so let us suppose that . Let us call a basic path any subpath of linking two distinct vertices of and with no interior vertices in . All the basic paths are on at least vertices because the girth of is at least . Now we consider two cases:
Case 1: for all basic paths of there exists an interior vertex of that has degree two in . Then, let . For all basic paths , if , then let be a vertex of degree two (in ) of , let and go the next path . At the end of this loop, one vertex of degree two is deleted from all basic paths. Remark that one vertex can be contained in several basic paths. Hence, contains no more cycle, but is still connected because the deleted vertices have all degree 2 and exactly one is deleted in each basic path. Hence, we obtain a tree that covers . This takes time because we enumerate all the pairs to find the basic paths.
Case 2: we are not in Case 1, so there exists a basic path whose interior vertices are all of degree at least 3 in . Then, since has terminals, Lemma 2.1 says that it has at most branchvertices. On the other hand, since a basic path is on at least vertices (because the girth is at least ), contains at least branchvertices of . So in fact, because , we have and contains all the branchvertices of . Since has no interior vertex of degree 2, in fact contains vertices. We name the vertices of . Note that is adjacent to and because is a basic path. In particular, and are not terminals of .
For all , is a cutvertex of that isolates one terminal among from all the other terminals. Up to relabelling, we suppose that this terminal is . We name the unique path of between and .
Note that is not adjacent to (because is a basic path). So the second outcome of our lemma holds, unless has at least one neighbor in some . For , we let be the neighbor of along , if has a neighbor in then we name the neighbor of closest to along and if no such neighbor exists, we put .
Suppose that for all we have . Then, the paths , together with and form a graph with a unique cycle: . By deleting a vertex such that , we obtain a tree that covers .
Hence, we may assume that for some , and up to symmetry we suppose . Then is a cycle on vertices, so because of the girth. Hence, , so . Then the paths , , together with form a tree that covers . ∎
A graph is a structure with respect to distinct terminals if it is made of vertexdisjoints paths of length at least one , …, such that the only edges between them are , , …, , .
Lemma 2.3
Let be an integer. Let be a connected graph of girth at least and be terminals where . Then either contains a tree that covers the terminals or and contains a structure with respect to .
This is algorithmic in the sense that we provide an algorithm that finds the tree or the structure.
Proof.
We suppose that is fixed and we prove the statement by induction on . For and , the lemma is clear: a tree exists (for instance, a shortest path linking the two terminals). Suppose the lemma holds for some and let us prove it for . By the induction hypothesis there exists an induced tree of that covers . Let be a path from to some vertex that has neighbors in , and suppose that is minimal with respect to this property. Then, no vertex of has a neighbor in .
We apply Lemma 2.2. If the first outcome holds, we have our tree. Otherwise, is a structure. All this can be implemented in time because terminals are taken one by one, there are at most of them and for each of them we rely on basic subroutines like BFS (Breadth First Search, see [4]) to find and on the algorithm of Lemma 2.2. ∎
3 The structure
A graph is a stucture with respect to 6 distinct terminals if it is made of 6 vertexdisjoints paths of length at least one , , , , , and four vertices such that the only edges between them are , , , , , , , , , , , . (See Figure 2.) We put .
We use the following ordering of the vertices , , , : . We say that a structure in a graph decomposes if the two following conditions hold:

for all such that , is a cutset of that separates from ;

for all such that , is a cutset of that separates from .
Lemma 3.1
If a graph of girth 6 contains a structure with respect to 6 terminals then one and only one of the following outcomes holds:

decomposes ;

contains a tree that covers .
This is algorithmic in the sense that if is given, testing whether decomposes or outputing the tree can be performed in time .
Proof.
Let us first check that at most one of the output holds. Suppose that the first outcome holds, and let be a connected induced subgraph of covering . Then must contain at least three vertices among , because if it fails to contain two of them, say , then is isolated from the rest of the graph because of Condition 1. Hence, we may assume that contains . Also, because of Condition 2, must contain , and . Hence, contains the cycle . Hence, cannot be a tree, so the second outcome fails.
Now let be an induced subgraph of that contains and such that decomposes ( exists since decomposes ). We show that for any vertex of , either is decomposed by or contains a tree covering . This will prove the theorem by induction and will be the description of an algorithm since for each , the proof gives the way to actually build the tree when there is one by calling the algorithm of Lemma 2.2 and searching the graph (with BFS for instance). Note also that testing whether decomposes some graph can be performed in linear time by 12 checks of connectivity.
Suppose that is not decomposed by . From the definition of decomposition, there are two cases:
Case 1: Condition 1 fails. Up to symmetry, we suppose that is a not cutset of that separates from . Let (resp. ) be the connected component of that contains (resp. that contains ). Hence, has a neighbor in and a neighbor in . Let be a shortest path in from to some vertex that has a neighbor in . Note that must go through . Because is a tree that covers , we may apply Lemma 2.2 to and in . Hence, either we find the tree or has exactly two neighbors in that have degree 2 in and that are adjacent to or . Since the girth is 6, we may assume up to symmetry that these two neighbors are and . Because of the girth 6, is not adjacent to , and .
If has a neighbor in , we let be a shortest path from to in . Otherwise, we let . We observe that is a tree that covers .
Case 2: Condition 1 is satisfied but Condition 2 fails. Up to symmetry, we suppose that is a not cutset of that separates from . Let us consider a path in from to some vertex in and let us suppose is minimal with respect to this property. Since Condition 1 is satisfied, must be from to or ( say). Note that the neighbor of along cannot be adjacent to (or there is a cycle on 4 vertices). We observe that is a tree that covers . ∎
4 The structure
For structures, we assume that notation like in the definition is used. We put . We say that a structure in a graph decomposes if for all such that , is a cutset of that separates from .
Lemma 4.1
Let be an integer. If a graph of girth at least contains a structure with respect to terminals then one of the following outcomes holds:

decomposes ;

and there exists a vertex of such that is a structure with respect to ;

contains a tree that covers .
This is algorithmic in the sense that testing whether decomposes or outputing the tree or outputing a ralebelling showing that is a structure can be performed in time .
Proof.
Let be an induced subgraph of that contains and such that decomposes ( exists since decomposes ). We show that for any vertex of , either satisfies the first outcome or is a structure or contains a tree covering . This will prove the theorem by induction and be the description of an algorithm since for each , the proof gives the way to actually build the tree or the relabelling by calling the algorithm of Lemma 2.2 and searching the graph (with BFS for instance). Note also that testing whether decomposes some graph can be performed in time , or since , by checks of connectivity.
Suppose that is not decomposed by . Let (resp. ) be the connected component of that contains (resp. that contains ). Up to symmetry, we may assume that has a neighbor in and a neighbor in . Let be a shortest path in from to some vertex that has a neighbor in . Note that must go through . Because is a tree that covers , we may apply Lemma 2.2 to and in . Hence, either we find the tree or has exactly two neighbors in and must be one of the folowing: , , , where denotes the neighbor of along .
When , we observe that is a square, i.e. a cycle on 4 vertices, contradicting our assumption on the girth.
When (or symmetrically ), then is not adjacent to (otherwise is a square). If has a neighbor in , we let be a shortest path from to in . Otherwise, we let . We observe that is a tree that covers .
We are left with the case when . Suppose first that has no neigbhor in . Then is a tree that covers . Suppose now that has a neighbor in . We let be a shortest path from to in . If then induces a tree that covers . If then we observe that induces a tree that covers .
So we may assume that is one of , . If then is a so because of the girth assumption. Hence is a tree that covers . So we are left with the case when . Then is a , so or because of the girth. If then is a tree that covers . If then is a structure as shown by the following relabelling: , , , , , , , , , , , , , , , . ∎
5 The main result
Theorem 5.1
Let be an integer. Let be a connected graph of girth at least and be terminals of . Then one and only one of the following holds:

contains structure with respect to and decomposes ;

, contains a structure with respect to and decomposes ;

contains a tree covering .
This is algorithmic in the sense that we provide an algorithm that output the tree or the structure certifying that no such tree exists in time .
Proof.
By Lemma 2.3, we can output a tree covering or a structure of in time . If a structure is ouptut, then by Lemma 4.1, we can check whether decomposes (in which case no tree exists) or find a tree, or find a structure . In this last case, by Lemma 3.1, we can check whether decomposes or find a tree. ∎
Theorem 5.2
Let be an integer. Let be a connected graph of girth at least and be vertices of . Deciding whether contains an induced tree covering can be performed in time .
Remark: In all the proofs above for , we use very often that the input graph contains no triangle and no square. Forbidding longer cycles is used less often. This suggests that the inatree problem might be polynomial for graphs with no triangle and no square. We leave this as an open question.
References
 [1] M. Chudnovsky and P. Seymour. Excluding induced subgraphs. In Surveys in Combinatorics, volume 346, pages 99–119. London Mathematical Society Lecture Notes Series, 2007.
 [2] M. Chudnovsky and P. Seymour. The threeinatree problem. Combinatorica. To appear.
 [3] N. Dehry, C. Picouleau, and N. Trotignon. The fourinatree problem in trianglefree graphs. Graphs and Combinatorics, 25:489–502, 2009.
 [4] A. Gibbons. Algorithmic Graph Theory. Cambridge University Press, 1985.
 [5] B. Lévêque, D. Lin, F. Maffray, and N. Trotignon. Detecting induced subgraphs. Discrete Applied Mathematics, 157:3540–3551, 2009.