Algorithms for Outerplanar Graph Roots and Graph Roots of Pathwidth at Most 2

Deciding if a graph has a square root is a classical problem, which has been studied extensively both from graph-theoretic and algorithmic perspective. As the problem is NP-complete, substantial effort has been dedicated to determining the complexity of deciding if a graph has a square root belonging to some specific graph class H\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathcal {H}}}$$\end{document}. There are both polynomial-time solvable and NP-complete results in this direction, depending on H\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathcal {H}}}$$\end{document}. We present a general framework for the problem if H\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\mathcal{H}$$\end{document} is a class of sparse graphs. This enables us to generalize a number of known results and to give polynomial-time algorithms for the cases where H\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathcal {H}}}$$\end{document} is the class of outerplanar graphs and H\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathcal {H}}}$$\end{document} is the class of graphs of pathwidth at most 2.


Introduction
Squares and square roots of graphs form a classical and well-studied topic in graph theory, which has also attracted significant attention from the algorithms community.A graph G is the square of a graph H if G and H have the same vertex set, and two vertices are adjacent in G if and only if the distance between them is at most 2 in H.This situation is denoted by G = H 2 , and H is called a square root of G.A square root of a graph need not be unique; it might even not exist.There are graphs without square roots, graphs with a unique square root, and graphs with several different square roots.Characterizing and recognizing graphs with square roots has therefore been an intriguing and important problem both in graph theory and in algorithms for decades.
Already in 1967, Mukhopadhyay [25] proved that a graph G on vertex set {v 1 , . . ., v n } has a square root if and only if G contains complete subgraphs {K 1 , . . ., K n }, such that each K i contains v i , and vertex v j belongs to K i if and only if v i belongs to K j .Unfortunately, this characterization does not yield a polynomial-time algorithm for deciding whether G has a square root.Let us Supported by the Research Council of Norway via the project "CLASSIS" and the Leverhulme Trust (RPG-2016-258).
formally call Square Root the problem of deciding whether an input graph G has a square root.In 1994 it was shown by Motwani and Sudan [24] that Square Root is NP-complete.Motivated by its computational hardness, special cases of the problem have been studied, where the input graph G belongs to a particular graph class.According to these results, Square Root is polynomialtime solvable on planar graphs [21], and more generally, on every non-trivial minor-closed graph class [26].Polynomial-time algorithms exist also when the input graph G belongs to one of the following graph classes: block graphs [19], line graphs [22], trivially perfect graphs [23], threshold graphs [23], graphs of maximum degree 6 [4], graphs of maximum average degree smaller than 46  11 [12], graphs with clique number at most 3 [13], and graphs with bounded clique number and no long induced path [13].On the negative side, it has been shown that Square Root is NP-complete on chordal graphs [16].A number of parameterized complexity results exist for the problem [4,5,12].
More interesting from our perspective, the intractability of the problem has also been attacked by restricting the properties of the square root that we are looking for.In this case, the input graph G is arbitrary, and the question is whether G has a square root that belongs to some graph class H specified in advance.We denote this problem by H-Square Root, and this is exactly the problem variant that we focus on in this paper.
Significant advances have been made also in this direction.Previous results show that H-Square Root is polynomial-time solvable for the following graph classes H: trees [21], proper interval graphs [16], bipartite graphs [15], block graphs [19], strongly chordal split graphs [20], ptolemaic graphs [17], 3-sun-free split graphs [17], cactus graphs [11], and graphs with girth at least g for any fixed g ≥ 6 [10].The result for 3-sun-free split graphs has been extended to a number of other subclasses of split graphs in [18].Observe that if H-Square Root is polynomial-time solvable for some class H, then this does not automatically imply that H -Square Root is polynomial-time solvable for a subclass H of H.
On the negative side, H-Square Root remains NP-complete for each of the following graph classes H: graphs of girth at least 5 [9], graphs of girth at least 4 [10], split graphs [16], and chordal graphs [16].All known NP-hardness constructions involve dense graphs [9,10,16,24], and the square roots that occur in these constructions are dense as well.This, in combination with the listed polynomial-time cases, naturally leads to the question whether H-Square Root is polynomial-time solvable if the class H is "sparse" in some sense.
Motivated by the above, in this paper we study H-Square Root when H is the class of outerplanar graphs, and when H is the class of graphs of pathwidth at most 2. In both cases, we show that H-Square Root can be solved in polynomial time.In particular, we prove that Outerplanar (Square) Root can be solved in time O(n 4 ) and (Square) Root of Pathwidth ≤ 2 in time O(n 6 ).Our approach for outerplanar graphs can in fact be directly applied to every subclass of outerplanar graphs that is closed under edge deletion and that can be expressed in monadic second-order logic, including cactus graphs, for which a polynomial-time algorithm is already known.

Preliminaries
We consider only finite undirected graphs without loops and multiple edges.We refer to the textbook by Diestel [8] for any undefined graph terminology.
Let G be a graph.We denote the vertex set of G by V G and the edge set by E G .The subgraph of G induced by a subset U ⊆ V G is denoted by G[U ].The graph G − U is the graph obtained from G after removing the vertices of U .If U = {u}, we also write G − u.Similarly, we denote the graph obtained from G by deleting a set of edges S, or a single edge e, by G − S and G − e, respectively.
The distance dist G (u, v) between a pair of vertices u and v of G is the number of edges of a shortest path between them.The open neighborhood of a A connected component of G is a maximal connected subgraph.A vertex u is a cut vertex of a graph G with at least two vertices if G−u has more components than G.A connected graph without cut vertices is said to be biconnected.An inclusion-maximal induced biconnected subgraph of G is called a block.
For a positive integer k, the k-th power of a graph H is the graph G = H k with vertex set V G = V H such that every pair of distinct vertices u and v of G are adjacent if and only if dist H (u, v) ≤ k.For the particular case k = 2, H 2 is a square of H, and The contraction of an edge uv of a graph G is the operation that deletes the vertices u and v and replaces them by a vertex w adjacent to (N G (u) ∪ N G (v)) \ {u, v}.A graph G is a contraction of a graph G if G can be obtained from G by a series of edge contraction.A graph G is a minor of G if it can be obtained from G by vertex deletions, edge deletions and edge contractions.
A graph G is planar if it admits an embedding on the plane such that there are no edges crossing (except in endpoints).A planar graph G is outerplanar if it admits a crossing-free embedding on the plane in such a way that all its vertices are on the boundary of the same (external) face.For a considered outerplanar graph, we always assume that its embedding on the plane is given.If G is a planar biconnected graph different from K 2 , then for any of its embeddings, the boundary of each face is a cycle (see, e.g., [8]).If G is a biconnected outerplanar graph distinct from K 2 , then the cycle C forming the boundary of the external face is unique and we call it the boundary cycle.By definition, all vertices of G are laying on C, and every edge is either an edge of C or a chord of C, that is, its endpoints are vertices of C that are non-adjacent in C. Clearly, these chords are not intersecting in the embedding.For a vertex u, we define the canonical ordering with respect to u as a clockwise ordering of the vertices on C starting from u.For a subset of vertices X, the canonical canonical ordering of X with respect to u is the ordering induced by the canonical ordering of the vertices of C. See Figure 1 a) for some examples.In our paper we use these terms for blocks of an outerplanar graphs distinct from K 2 .Outerplanar graphs can also be characterized via forbidden minors as shown by Sys lo [28].
Fig. 1. a) Canonical orderings with respect to u of a biconnected outerplanar graph with vertex set VG = {v1, . . ., vn} and a set X = {x1, . . ., x k }. b) Example of a set X = {x1, x2, x3} that is consecutive with respect to u; notice that x1 and x3 are not consecutive.

Lemma 1 ([28]
).A graph G is outerplanar if and only if it does not contain K 4 and K 2,3 as minors.
A tree decomposition of a graph G is a pair (T, X) where T is a tree and X = {X i | i ∈ V T } is a collection of subsets (called bags) of V G such that the following three conditions hold: The width of a tree decomposition The treewidth tw(G) of a graph G is the minimum width over all tree decompositions of G.If T is restricted to be a path, then we say that (X, T ) is a path decomposition of G, The pathwidth pw(G) of G is the minimum width over all path decompositions of G. Notice that a path decomposition of G can be seen as a sequence (X 1 , . . ., X r ) of bags.We always assume that the bags (X 1 , . . ., X r ) are distinct and inclusion maximal, that is, there are no bags X i and X j such that X i ⊂ X j .
The following fundamental results are due to Bodlaender [1], and Bodlaender and Kloks [3].
Lemma 2 ( [1,3]).For every fixed constant c, it is possible to decide in linear time whether the treewidth of a graph is at most c.For every fixed constant c, it is possible to decide in linear time whether the pathwidth of a graph is at most c.
We need the following three folklore observations about treewidth and pathwidth.
Observation 1 If H is a minor (contraction) of G, then tw(H) ≤ tw(G) and pw(H) ≤ pw(G).
Observation 3 For a graph G and a positive integer k, For more information on treewidth and pathwidth we refer to [2].
Let H be a square root of a graph G.We say that H is a minimal square root of G if H 2 = G, and no proper subgraph of H is a square root of G.We need the following simple observations.Observation 4 Let H be a graph class closed under edge deletion.If a graph G has a square root H ∈ H, then G has a minimal square root that belongs to H.
Observation 5 Let H be a minimal square root of a graph G that contains three pairwise adjacent vertices u, v, w.Then v or w has a neighbor x = u in H such that x is not adjacent to u.
Proof.Since H is a minimal square root of G, H − vw is not a square root of G.Because uv, uw ∈ E G , we conclude that there is xy ∈ E G \ E H such that H has a unique (x, y)-path P of length two and wv is an edge of this path.Then P = xvw or P = xwv for some x = u that is not adjacent to u.
We conclude this section by a lemma that enables us to identify some edges that are not included in any square root.The lemma is implicit in [11]; for the sake of completeness we give a full proof here.Lemma 3. Let x, y be distinct neighbors of a vertex u in a graph G such that x and y are at distance at least 3 in G − u.

Outerplanar Roots
In this section we show that it can be decided in polynomial time whether a graph has an outerplanar square root.We say that a square root H of G is an outerplanar root if H is outerplanar.We define the following problem: Outerplanar Root Input: a graph G. Question: is there an outerplanar graph H such that H 2 = G?
The main result of this section is the following.
Theorem 1. Outerplanar Root can be solved in time O(n 4 ), where n is the number of vertices of the input graph.
The remaining part of this section is devoted to the proof of Theorem 1.In Section 3.1 we obtain several structural results we need to construct an algorithm for Outerplanar Root.Then in Section 3.2 we construct a polynomial-time algorithm for Outerplanar Root.

Structural Lemmas
In this section we give several structural results about outerplanar square roots.
Let H be an outerplanar root of a graph G, u ∈ V G .We say that two distinct vertices x, y ∈ N H (u) are consecutive with respect to u if x and y are in the same block F of H and there are no vertices of N H (u) between x and y in the canonical ordering of the vertices of the boundary cycle of F with respect to u.For a set of vertices X ⊆ N H (u), we say that the vertices X are consecutive with respect to u if the vertices of X are in the same block of H and any two vertices of X consecutive in the canonical ordering of elements of X with respect to u are consecutive with respect to u; a singleton is assumed to be consecutive (see Figure 1 b for an example).
As every subgraph of an outerplanar graph is outerplanar, by Observation 4, we may restrict ourselves to minimal outerplanar roots.Let H be a minimal outerplanar root of a graph G and let u ∈ V G .Denote by S(G, H, u) a collection of all subsets X of N H (u) such that X = N G (x) ∩ N H (u) for some x ∈ N G (u) \ N H (u). We intend to use the notion S(G, H, u) to find edges of G which cannot belong to any square root of G. To this aim we study properties of S(G, H, u).Lemma 4. Let H be a minimal outerplanar root of a graph G, and let u ∈ V G .Then for each X ∈ S(G, H, u), X is consecutive with respect to u.
then the claim holds by definition.Assume that |X| ≥ 2. Notice that the vertices of X are in the same block of H, because if y, z ∈ N H (u) are not in the same block F of H, then any vertex adjacent to y and z in G is in N H [u]. Assume that X = {x 1 , . . ., x k } and the vertices are numbered in the canonical order with respect to u. Suppose that X is not consecutive with respect to u.Then there is a vertex y lying on C between x i−1 and x i for some i ∈ {2, . . ., k} such that uy ∈ E H and yx / ∈ E G .Since x i−1 x, x i x ∈ E G , H has (x i−1 , x) and (x i , x)-paths P 1 and P 2 of length at most 2. Notice that these paths do not contain u, because xu / ∈ E H , and they do not contain y, because yx / ∈ E G .This implies that y is inside of the inner face of C in the outerplanar embedding of G; a contradiction.

Lemma 5. Let H be a minimal outerplanar root of a graph G, and let
Proof.Suppose that for two distinct x, y ∈ N H (u), xy ∈ E H .By Observation 5, there is a vertex z such that z is adjacent to x or y in H, but z is not adjacent to u in H.We obtain that x and y are adjacent to z in G and, therefore, We also need the following two observations.Lemma 6.Let H be a minimal outerplanar root of a graph G, and Proof.Since x is not a pendant vertex, it has a neighbor in H distinct from u.If there is a y ∈ N H (x) such that y / ∈ N H [u], the claim holds.Assume that for every y ∈ N H (x) distinct from u, it holds that y ∈ N H (u). Consider such a neighbor y of u.By Observation 5, y has a neighbor z in Lemma 7. Let H be a minimal outerplanar root of a graph G, and let u ∈ V G .Then any X ∈ S(G, H, u) has size at most 4.
Proof.Suppose that there is a set . By Lemma 4, X is consecutive with respect to u, and w.l.o.g.x 1 , . . ., x k is the canonical order of the vertices of X along the boundary cycle C of the block of H with respect to u. Suppose that x lays on C. If it lays before x 3 in the canonical ordering of the vertices of C with respect to u, then x is not adjacent to x k in G by outerplanarity; a contradiction.Similarly, if x lays after x 3 , x is not adjacent to x 1 in G and we also have a contradiction.Suppose that x does not belong to C. Then x is at distance at most 2 in H from x 1 and x k .It follows that there is a (x 1 , x k )-path P in H of length at most 4 avoiding u and at least one vertex of X but this contradicts outerplanarity.
By combining Lemmas 4 and 7 we obtain the following lemma.Lemma 8. Let H be a minimal outerplanar root of a graph G, and let u ∈ V G .Then the following holds.
in the canonical order with respect to u in the boundary cycle of F , then for any X ∈ S(G, H, u), x i / ∈ X or x j / ∈ X if i, j ∈ {1, . . ., k} and |i − j| ≥ 4.
We now state some structural results that help to decide whether an edge incident to a vertex is in an outerplanar root or not.Suppose that u and v are pendant vertices of a square root H of G and that u and v are adjacent to the same vertex of H − {u, v}.Then, in G, u and v are simplicial vertices and true twins.We use this observation in the proof of the following lemma that allows to find some pendant vertices.Lemma 9. Let H be a minimal outerplanar root of a graph G.If G contains at least 7 simplicial vertices that are pairwise true twins, then at least one of these vertices is a pendant vertex of H.
Proof.Let H be a minimal outerplanar root of a graph G that contains a set X of 7 simplicial vertices that are pairwise true twins.
Suppose first that X contains two vertices x and y that do not belong to the same block of H.We claim that x is a pendant vertex of H. Since x and y are adjacent in G, we obtain that xu, yu ∈ E H for a cut vertex u that belongs to two blocks F x and F y of H containing x and y respectively.To obtain a contradiction, assume that x has a neighbor z = u in H. Clearly, z is not in F y .It implies that zu ∈ E H , because x and y are true twins of G and, therefore, z ∈ N G (y).Since H is a minimal square root, H − xz is not a square root of G.Because ux, uz ∈ E H , we have that there is a vertex ∈ E H and zxz is the unique (z, z )-path of length at most 2 in H or, symmetrically, ii) xz / ∈ E H , zz ∈ E H and xzz is the unique (x, z )-path of length at most 2 in H.Because x and y are true twins of G and z = u, we obtain that yz ∈ E G and, therefore, uz ∈ E H . Hence, xuz and zuz are paths of H contradicting i) or ii) respectively.We conclude that x is a pendant vertex of H.
Suppose now that the vertices of X belong to the same block F of H. Let C be the boundary cycle of F and denote by x 1 , . . ., x 7 the vertices of X numbered according to the canonical order with respect to an arbitrary vertex of C. Because the vertices of X are pairwise adjacent in G, F has a chord uv such that X has vertices in the two components of F − {u, v}.Among all such chords we choose uv and a component F of F −{u, v} in such a way that F contains the minimum number of vertices of X.Let F be the other compoent of F − {u, v}.Assume without loss of generality that x 1 ∈ V F and let x i , . . ., x j for 1 < i ≤ j ≤ 7 be the vertices of X in F .Notice that F contains at least 3 vertices of X by the choice of uv.Assume also that v is after x 1 in the canonical ordering of the vertices of C with respect to u.Because the vertices of X are adjacent in G, they are at distance at most 2 in H.It implies that for any x ∈ X ∩ V F and any y ∈ X ∩ V F , xu, uy ∈ E H or xv, vy ∈ E H by the outerplanarity of F .Suppose that F contains at least two vertices of X.By symmetry, we can assume that ∈ E H by the choice of uv.We obtain that x i u ∈ E H and x j v ∈ E H , but these are intersecting chords of C; a contradiction.We conclude that x 1 is the unique vertex of X in F .Notice that it implies that i ≤ 3 and j ≥ 6 but it can happen that u = x 7 or v = x 2 .We also have that Hence, u is adjacent to x 1 , . . ., x 6 in this case.
Suppose that x 1 v ∈ E H .We show that either x k u ∈ E H for k ∈ {i, . . ., j} or x k v ∈ E H for k ∈ {i, . . ., j}.Assume that this is not the case and that there is an s ∈ {i, . . ., j} such that x s u / ∈ E H and t ∈ {i, . . ., j} such that we have that the distance between x i and x j in H is at least 3 by the outerplanarity of H, a contradiction.Therefore, the claim holds.By symmetry, we can assume that x k u ∈ E H for k ∈ {i, . . ., j}.In particular, u is adjacent to x 1 , . . ., x 6 We now show that x 3 is a pendant vertex of H.To obtain a contradiction, assume that x 3 has a neighbor y in H distinct from u.Because x 3 and x 6 are true twins of G, yx 6 ∈ E G and, therefore, yu ∈ E H and yx 3 z is the unique (y, z)-path in H or, symmetrically, ii) x 3 z / ∈ E H , yz ∈ E H and x 3 yz is the unique (x 3 , z)-path in H.If x 3 z ∈ E H , then by the same arguments as for y, we have that zu ∈ E H and we get another path yuz.Let yz ∈ E H .If z ∈ {x 1 , . . ., x 5 }, then zu ∈ E H and we have the path x 3 uz.Hence, z / ∈ {x 1 , . . ., x 5 }.Since z is adjacent to x 3 in G, z is a neighbor of x 6 in G.The only possibility is that zx 4 , zx 5 ∈ E H , i.e., z lays in C between x 4 and x 5 .Since z is adjacent to x 1 , we obtain that uz ∈ E H . Again, we have the path x 3 uz; a contradiction.We conclude that x 3 is a pendant vertex of H.
We apply Lemma 3 to identify the edges incident to a vertex of sufficiently high degree in an outerplanar root using the following two lemmas.
Lemma 10.Let G be a graph having a minimal outerplanar root H. Let also u ∈ V G be such that there are three distinct vertices ∈ E H . Suppose that there is an i ∈ {1, 2, 3} such that x and v i are in distinct components of H − u.Then any (x, v i )-path in H goes through u and has length at least 4, because ux, Suppose now that v 1 , v 2 , v 3 and x are in the same component of Let F be a block of H containing u and y and denote by C its boundary cycle.Because v 1 , v 2 , v 3 and x are in the same component of H − u, each v i is either i) a vertex of F and we let v i = v i in this case or ii) v i / ∈ V F and there is a unique 2).Assume that v 1 , v 2 , v 3 is the canonical order with respect to u in C.
Let y = v 2 .If y lays before v 2 on C in the canonical ordering with respect to u, x is either before or after v 2 in the canonical ordering with respect to u.We have that dist Lemma 11.Let G be a graph having a minimal outerplanar root H such that any vertex of H has at most 7 pendant neighbors.Let also Proof.Let H be a minimal outerplanar root of G such that any vertex of H has at most 7 pendant neighbors and let u ∈ V G be a vertex with d H (u) ≥ 22. Denote by A the set of pendant neighbors of u and let Suppose that the vertices of X are in at least 3 distinct components of H − u.Then there are distinct blocks F 1 , F 2 and F 3 of H containing u and at least one vertex of X each.By Lemma 6, there are We obtain that they are pairwise at distance at least 3 in G − u.
Suppose now that the vertices of X are in exactly two distinct components of H − u.Then there are two blocks F 1 and F 2 of H containing u and the vertices of X.Since |X| ≥ 15, we can assume that F 1 contains at least 8 vertices of X. Denote them by x 1 , . . ., x k in their order in the canonical order in the boundary cycle of F 1 with respect to u.By Lemma 6, there are Notice that each of v 1 and v 2 is either laying on the boundary cycle of F 1 or is in another block of H containing x 1 or x 2 and Finally, assume that the vertices of X are in the same block F of H. Denote them by x 1 , . . ., x k in their order in the canonical order in the boundary cycle of F with respect to u.By Lemma 6, there are By Lemmas 4 and 7, v 1 is not adjacent in G to x 5 , . . ., x k , v 2 is not adjacent to x 1 , . . ., x 4 and x k−3 , . . ., x k , and v k is not adjacent to x 1 , . . ., x k−4 .Notice that each of v 1 , v 2 and v 2 is either laying on the boundary cycle of F or is in another block of H containing x 1 or x 2 , x 7 or x 8 or x 9 and x k−1 or x k respectively.Then dist G−u (v i , v j ) ≥ 3 for i, j ∈ {1, 2, 3}, i = j.
The next lemma is crucial for our algorithm.To state it, we need some additional notations.Let H be a minimal outerplanar root of a graph G such that each vertex of H is adjacent to at most 7 pendant vertices.Let U be a set of vertices of H that contains all vertices of degree at least 22.For every u ∈ U and every block F of H containing u we do the following.Consider the set X = N H (u) ∩ V F and denote the vertices of X by x 1 , . . ., x k , where these vertices are numbered in the canonical order with respect to u.Then for i, j ∈ {1, . . ., k}, delete the edge for i ∈ {1, . . ., k}, delete the edges Denote by G (H, U ) the graph obtained by this procedure.
Lemma 12.There is a constant c that depends neither on G nor on H such that tw(G (H, U )) ≤ c.
Proof.Let H be a minimal outerplanar root of a graph G such that each vertex of H is adjacent to at most 7 pendant vertices.Let U be a set of vertices of H containing the vertices of degree at least 22.For each vertex u ∈ U we do the following.
-Let F 1 , . . ., F r be the blocks of H containing u.
-For each i ∈ {1, . . ., r}, denote by x i 1 , . . ., x i ki the neighbors of u in F i numbered according to the canonical ordering with respect to u for the boundary cycle of F i .Assume that x 0 , . . ., x k is the ordering of N H (u) obtained by the consecutive concatenation of the sequences x i 1 , . . ., x i ki for i = 1, . . ., r.
-Modify H as follows: delete u, replace it by a path u 1 . . .u k and make each u i adjacent to x i−1 and x i for i ∈ {1, . . ., k} (see Figure 3).
Denote by Ĥ the graph obtained by the procedure.Notice that the procedure modifies degrees of vertices of H but we do not recompute U .
Notice that H is a contraction of Ĥ as H can be obtained from Ĥ by contracting the paths u 1 . . .u k constructed for u ∈ U .It is also straightforward to see that Ĥ is an outerplanar graph, because each step maintains outerplanarity (see Figure 3).By Observation 2, tw( Ĥ) ≤ 2.
We claim that ∆( Ĥ) ≤ 42.Let v ∈ V Ĥ .Suppose first that v ∈ V H \ U .We have that d H (v) ≤ 21 and, in particular, v has at most 21 neighbors in U in the graph H.In the construction of Ĥ each neighbor of this type is replaced by two neighbors and all other neighbors remain the same.Therefore, d Ĥ (v) ≤ 42.Suppose now that v is a vertex of one of the paths u 1 . . .u k constructed for u ∈ U .Notice, that when u is replaced by u 1 . . .u k , then the degree of each vertex u i is at most 4, and at most two neighbors of u i could be modified in the subsequent construction steps.It implies that d Ĥ (v) ≤ 6.
We claim that G (H, U ) is a minor of Ĥ4 .
Let Ĝ be the graph obtained from Ĥ4 by the contraction of the paths u 1 . . .u k constructed for u ∈ U .We use the name u for the vertex obtained by contracting u 1 . . .u k constructed for u ∈ U .Thus, we can assume that V Ĝ = V G .We show that G (H, U ) is a subgraph of Ĝ.
We already observed that H can be obtained from Ĥ by contracting paths u 1 . . .u k constructed for u ∈ U .Hence, each edge of H is an edge of Ĝ.Let xy be an edge of G (H, U ) that is not an edge of H.Then, there is u ∈ V G such that xu, yu ∈ H. Denote by X and Y respectively the sets of vertices of Ĥ that are contracted to x and y respectively.If u / ∈ U , then by the construction of Ĥ, there are x ∈ X and y ∈ Y such that x u, y u ∈ E Ĥ .Hence, x y ∈ Ĥ4 and xy ∈ E Ĝ. Suppose that u ∈ U .By the definition of G (H, U ), the vertices x and y are in the same block F of H. Denote by z 1 , . . ., z k the vertices of N H (u) in F in the canonical order with respect to u along the boundary cycle of F .We have that x = z i and y = z j for some i, j ∈ {1, . . ., k}.By the definition of G (H, U ), |i − j| ≤ 4. By the construction of Ĥ, there are x ∈ X and y ∈ Y that are joined by the path x z i+1 . . .z j y in Ĥ.Since this path has length at most 4, x y ∈ Ĥ4 .Therefore, xy ∈ Ĝ.
Since G (H, U ) is a subgraph of Ĝ and Ĝ is a contraction of Ĥ4 , we conclude that G (H, U ) is a minor of Ĥ4 .

The Algorithm
In this section we construct an algorithm for Outerplanar Root with running time O(n 4 ).Let G be the input graph.Clearly, it is sufficient to solve Outerplanar Root for connected graphs.Hence, we assume that G is connected and has n ≥ 2 vertices.
First, we preprocess G using Lemma 9 to reduce the number of pendant vertices adjacent to the same vertex in a (potential) outerplanar root of G. To do so, we exhaustively apply the following rule.
Pendants reduction.If G has a set X of simplicial true twins of size at least 8, then delete an arbitrary u ∈ X from G.
The following claim shows that this rule is safe.
Lemma 13.If G = G − u is obtained from G by the application of Pendant reduction, then G has an outerplanar root if and only if G has an outerplanar root.
Proof.Suppose that H is a minimal outerplanar root of G.By Lemma 9, H has a pendant vertex u ∈ X.It is easy to verify that H = H −u is an outerplanar root of G .Assume now that H is a minimal outerplanar root of G .By Lemma 9, H has a pendant vertex w ∈ X \ {u}, since the vertices of X \ {u} are simplicial true twins of G and |X \ {u}| ≥ 7. Let v be the unique neighbor of w in H .We construct H from H by adding u and making it adjacent to v. It is readily seen that H is an outerplanar root of G.This completes the proof.
For simplicity, we call the graph obtained by exhaustive application of the pendants rule G again.The following property immediately follows from the observation that any two pendant vertices of a square root H of G adjacent to the same vertex in H are true twins of G. Lemma 14.Every outerplanar root of G has at most 7 pendant vertices adjacent to the same vertex.
In the next stage of our algorithm we label some edges of G red or blue in such a way that the edges labeled red are included in every minimal outerplanar root and the blue edges are not included in any minimal outerplanar root.We denote by R the set of red edges and by B the set of blue edges.We also construct a set of vertices U of G such that for every u ∈ U , the edges incident to u are labeled red or blue.
Labeling.Set U = ∅, R = ∅ and B = ∅.For each u ∈ V G such that there are three distinct vertices v 1 , v 2 , v 3 ∈ N G (u) that are at distance at least 3 from each other in G − u do the following: Next, we find the set of edges xy with xu, yu ∈ R for some u in R such that they cannot be edges in any minimal outerplanar root, and thus are irrelevant edges.
Finding irrelevant edges.Set S = ∅.For each u ∈ U and each pair of distinct x, y ∈ N G (u) such that ux, uy ∈ R do the following.
Proof.Let H be a minimal outerplanar root of G.By Lemma 16, E H ∩ S = ∅, i.e., E H ⊆ E G .Let L = E H .It is straightforward to verify that (i)-(iv) are fulfilled.Assume now that there is L ⊆ E G such that (i)-(iv) hold.Then we have that H = (V G , L) is an outerplanar root of G.
To complete the description of the algorithm, it remains to show how to check the existence of a set of edges L satisfying (i)-(iv) of Lemma 17 for given G , R and B. Notice, that if G has a minimal outerplanar root H, then G is a subgraph of the graph G (H, U ) constructed in Section 3.1 by Lemma 8.By Lemma 12, there is a constant c that depends neither on G nor on H such that tw(G (H, U )) ≤ c.Therefore, tw(G ) ≤ c for a yes-instance.We use Lemma 2 to verify whether it holds.If we obtain that tw(G ) > c, we conclude that we have a no-instance and stop.Otherwise, we use the celebrated theorem of Courcelle [6], which states that any problem that can be expressed in monadic second-order logic can be solved in linear time on graph of bounded treewidth.It is straightforward to see that properties (i)-(iv) can be expressed in this logic.In particular, to express outerplanarity in (iv), we can use Lemma 1 and the well-known fact that the property that G contains F as minor can be expressed in monadic second-order logic if F is fixed (see, e.g., the book of Courcelle and Engelfriet [7]).It immediately implies that we can decide in linear time whether L exists or not.Notice that we can modify these arguments such that we do not only check the existence of L but also find it.To do this, we can construct a dynamic programming algorithm for graphs of bounded treewidth that finds L. Now we evaluate the running time of our algorithm.We can find simplicial vertices of the input n-vertex graph G in time O(n 3 ).Therefore, Pendant reduction can be done in time O(n 3 ).For every vertex u, we can compute the distances between the vertices of N G (u) in G − u in time O(n 3 ).This implies that Labeling can be done in time O(n 4 ).Finding irrelevant edges also can be done in time O(n 4 ) by checking O(n 2 ) pairs of vertices x and y.Then G can be constructed in linear time.Finally, checking whether tw(G ) ≤ c and deciding whether there is a set of edges L satisfying the required properties can be done in linear time by Lemma 2 and Courcelle's theorem [6] respectively.
Notice that we can use the same arguments to decide whether a graph G has a square root H that belongs to some subclass H of the class of outerplanar graphs.To be able to apply our structural lemmas, we only need the property that H should be closed under edge deletions.Observe also that if the properties defining H could be expressed in monadic second-order logic, then we can apply Courcelle's theorem [6].It gives us the following corollary.
Corollary 1.For every subclass C of the class of outerplanar graphs that is closed under edge deletions and can be expressed in monadic second-order logic, it can be decided in time O(n 4 ) whether an n-vertex graph G has a square root H ∈ C.

Roots of Pathwidth at most two
Our main approach for solving Outerplanar root is general in the sense that it can be adapted to also find square roots belonging to some other graph classes.In this section, we show that there is an algorithm to decide in polynomial time whether a graph has a square root of pathwidth at most 2. Notice that graphs of pathwidth 1 are caterpillars, and that it can be decided in polynomial time whether a graph G has a square root that is a caterpillar by an easy adaptation of the algorithms for finding square roots that are trees [21,27].
We define the following problem: The main difference between our algorithm for Root of Pathwidth ≤ 2 and our algorithm for Outerplanar Root lies in the way properties of the involved graph classes are used.To show the structural results needed for this algorithm, we use the property that a potential square root has a path decomposition of width at most 2, instead of the existence of an outerplanar embedding used in the previous section.The remaining part of this section contains the proof of Theorem 2. In Section 4.1, we present the structural results necessary to prove correctness of the algorithm for Root of Pathwidth ≤ 2. The algorithm itself is presented in Section 4.2.

Structural Lemmas
In this section, we present structural properties of graphs with square roots of pathwidth at most 2. Recall that we assume that for any considered path decomposition, it holds that A B for every two distinct bags A and B of the decomposition.As the pathwidth of any subgraph of a graph of pathwidth at most 2 is upper bounded by 2, by Observation 4, we can consider only minimal roots of pathwidth at most 2.
Lemma 18.Let G be a graph and H be a minimal square root of G such that pw(H) ≤ 2. Suppose there exist distinct u, v, x 1 , . . ., x k such that the bags {x 1 , u, v}, {x 2 , u, v},. .., {x k , u, v} appear in this order in the path decomposition of H. Then for each i, 2 Proof.Suppose x i has a neighbor w in H such that w = u and w = v.Clearly there exists a bag B in the path decomposition of H that contains x i and w.As B contains x i , then B is between the bags {x 1 , u, v} and {x k , u, v} in the path decomposition and hence must contain u and v. Then |B| ≥ 4, a contradiction with pw(H) ≤ 2.
For two positive integers p and q, we denote by R(p, q) the Ramsey number, that is, the smallest n such that every graph on n vertices has either a clique of size p or an independent set of size q.Those numbers are all finite by Ramsey's theorem (see, e.g., [8]).
Lemma 19.Let G be a graph and H be a minimal square root of G such that pw(H) ≤ 2. Then there is a constant c 1 such that for every set W of true twins in G, if |W | ≥ c 1 , then one of the following holds: ).We start by constructing an auxiliary graph F .Let V F = W and two vertices of F are adjacent if there exists a bag in the path decomposition of H that contains both of them.We want to show that F has an independent set of size 16.To do so, we prove that F has no clique of 4 vertices.Suppose for the sake of contradiction that F has such a clique, say {x 1 , x 2 , x 3 , x 4 }.Let P i be the interval of those bags of the path decomposition of H that contain the vertex x i .By the construction of F , these intervals are pairwise intersecting.By the Helly property, there exists a bag containing all four vertices, a contradiction with pw(H) ≤ 2. Hence F has an independent set of size 16, since ) and F has no clique of 4 vertices.
Let W = {x 1 , x 2 , . . ., x 16 } be such an independent set of F .By the construction of F , there are no two vertices of W that are contained in the same bag of the path decomposition of H. Let B 1 , B 2 , . . ., B 16 be bags containing the vertices of W such that x i ∈ B i .As the vertices of W are true twins in G and they are not adjacent in H, there must exist a path of length two between any two of them.Let x 1 ux 16 be such path between x 1 and x 16 .We may consider that u ∈ B 1 , otherwise we can pick bag B 1 as the one containing x 1 and u.Analogously, we may assume that u ∈ B 16 .Since we have a path decomposition, we conclude that u ∈ B i , 2 ≤ i ≤ 15.
Suppose there are three distinct vertices x i , x j and x k in W that are not adjacent to u, with 2 ≤ i < j < k ≤ 15.Let v be a vertex in a path of length two between x i and x k , i.e. v is a common neighbor of x i and x k .We may assume that B i = {x i , u, v} and B k = {x k , u, v}.Then v ∈ B j .By Lemma 18 and by the fact that x j u / ∈ E H , we conclude that d H (x j ) = 1 and hence (i) holds.Suppose that at most two vertices of W \ {x 1 , x 16 } are not adjacent to u in H. Let W = {x 1 , . . ., x p }, p ≥ 12, be the set containing the vertices that are adjacent to u in W \ {x 1 , x 16 }.If some vertex of W has degree one in H, then condition (i) holds.Assume this is not the case.Then all the vertices of W have degree at least two in H. Let B = {B 1 , . . ., B p } be bags such that x i ∈ B i .Let v be a neighbor of x 1 , v = u.We may assume B 1 = {x 1 , u, v}.If v appears in at least five bags of B , then it appears in B 1 , B 2 , B 3 , B 4 and B 5 .As x 2 , x 3 and x 4 do not have degree one by hypothesis, then by Lemma 18, they have degree two and hence condition (ii) holds.As x 1 and x 16 are true twins in G, then v must also be a neighbor of x 16 in G.If v and x 16 are not adjacent, let vwx 16 be a path of length two between them.If w = u, the bag containing {v, w, u} has to be between {x 1 , u, v} and B 16 .Since p ≥ 12, either v or w appear in at least five bags of B .If w = u, then v, u and x 1 form a triangle in H.By Observation 5, there exists a vertex z that is adjacent to either v or x 1 that is not adjacent to u.The case when z is a neighbor of x 1 has already been covered.If G has a set W of true twins with size greater than c 1 , then we can delete an arbitrary vertex of W .The following lemma shows that this procedure is safe.Proof.Let G be a graph that has a square root H of pathwidth at most 2. Since |W | ≥ c 1 + 1, either there exists a vertex v ∈ W satisfying the condition (i) of Lemma 19 or there are three vertices v 1 , v 2 , v 3 ∈ W satisfying (ii).Since the vertices of W are true twins, we can assume that u = v in the first case and u = v 1 in the second.In both cases we obtain that H − u is a square root of pathwidth at most 2 for G − u.
To prove the other direction, let H be a square root of pathwidth at most 2 of G .Since |W \ {u}| ≥ c 1 , H has a vertex v satisfying the condition (i) of Lemma 19 or there are three vertices v 1 , v 2 , v 3 ∈ W satisfying (ii).
If v is a pendant, let w be the vertex of H that is adjacent to v.In order to obtain a square root H of G, we attach u to w in H .We now prove that pw(H) ≤ 2. We may assume that v appears in only one bag in the path decomposition of H (which also contains w).If this is not the case, we can delete all other occurrences of v and still obtain a valid path decomposition of H having width at most two.Let A i be the bag containing {w, v} and A i+1 be the next bag in the path decomposition.If w ∈ A i+1 , we create a new bag between A i and A i+1 containing and the new bag will contain (A i ∩ A i+1 ) ∪ {u, w}.This is a path decomposition for H of width at most two.
Assume that v 1 , v 2 , v 3 are vertices satisfying condition (ii) of Lemma 19.Let N H (v 1 ) = N H (v 2 ) = N H (v 3 ) = {w, y}.In order to obtain a square root H for G, we add u to V (H ) and make it adjacent to w and y.We now prove that pw(H) ≤ 2. Since N H (v 1 ) = N H (v 2 ) = N H (v 3 ) = {w, y}, there is a bag in the path decomposition of H containing A i = {w, y, v i } for some i ∈ {1, 2, 3}.Since v i is only adjacent to w and y, we may assume that this is the only bag in the decomposition containing v i .Let A i+1 be the bag that succeeds A i in the decomposition.We create a new bag between A i and A i+1 containing {u, w, y}, and hence obtain a path decomposition for H of width at most two.
For simplicity, let us denote the graph obtained by exhaustive application of the previously described safe procedure by G again.From now on, in all our lemmas, we assume that every set of true twins of G has size bounded by the constant c 1 .
Lemma 21.Let G be a graph and H be a minimal square root of G such that pw(H) ≤ 2. Suppose there exist distinct u, v, x 1 , . . ., x k such that the bags {x 1 , u, v}, {x 2 , u, v},. .., {x k , u, v} appear in this order in the path decomposition of H. Then k ≤ 3c 1 + 2.
Proof.By Lemma 18, for every 2 ≤ i ≤ k − 1, N H (x i ) ⊆ {u, v}.All vertices that are adjacent in H only to u are true twins in G.The same applies to vertices that are adjacent only to v and also to those that are adjacent to both u and v. Since the size of every set of true twins in G is bounded by c 1 , we have |{x 2 , . . ., x k−1 }| ≤ 3c 1 and hence k ≤ 3c 1 + 2.
Lemma 22.Let G be a graph and H be a minimal square root of G such that pw(H) ≤ 2. If u, v ∈ V H , then the number of common neighbors of u and v in H is bounded by c 1 + 2.
Proof.Suppose N H (u) ∩ N H (v) = {x 1 , . . ., x t }.In the path decomposition of H, for each i, we need a bag containing u and x i and a bag containing v and x i .As pw(H) ≤ 2, this implies the existence of one bag B i = {u, v, x i } for each i.Suppose B 1 , . . ., B t appear in the path decomposition in this order.Lemma 18 and the fact that {x 2 , . . ., x t−1 } ⊂ N H (u) ∩ N H (v) imply that the vertices x 2 , x 3 , . . ., x t−1 are true twins in G and that the number of such vertices is bounded by c 1 .Hence, the number of common neighbors of two vertices in H is bounded by c 1 + 2.
Lemma 23.Let G be a graph and H be a minimal square root of G such that pw We choose a set of bags B 1 , . . ., B l in the path decomposition of H such that u ∈ B i .Then for all i and for all x ∈ N H (u), there exists an i such that x ∈ B i .Note that some neighbors of u might appear in more than one bag.Let k 1 be the smallest integer such that ∪ k1 i=1 B i contains at least three distinct vertices of N H (u). Since u belongs to all bags, at least one of these three neighbors in ∪ k1 i=1 B i does not appear in B k1 .
Let v 1 be such a vertex.In general, let k j be the smallest integer greater than k j−1 such that ∪ kj i=kj−1 B i contains at least five new vertices of N H (u). Since u belongs to all bags, there is at least one vertex among the five that appears neither in B kj−1 nor in B kj .Let v j be such a vertex.Hence we obtain a set {v 1 , . . ., v t } ⊂ N H (u) that is an independent set.Since d H (u) ≥ c 2 = 6•21(c 1 +2), we have t ≥ 21(c 1 + 2).For each v i , we pick x i ∈ N H (v i ) such that x i = x j if i = j.Since t ≥ 21(c 1 + 2) and by Lemma 22, we can pick at least 21 such vertices.For simplicity, we assume that {v 1 , . . ., v 21 } is a set of such vertices.For each i, let A i be a bag containing v i and u.For 2 ≤ i ≤ 20, we can assume A i = {v i , x i , u}.Note that x i and x i+1 might be adjacent in H, but x i cannot be a neighbor of x k , with k ≥ i + 2, because of the existence of bag {v i+1 , x i+1 , u}.For the same reason, x i cannot be adjacent to v k for some k ≥ i + 2. Also, if k ≥ i + 2, all paths in H from x i to x k contain either x i+1 or v i+1 .The same applies to the paths from x i to v k for some k ≥ i + 2. Then {x 1 , x 6 , x 11 , x 16 , x 21 } are vertices that are pairwise at distance at least 3 in G − u.
Lemma 24.Let G be a graph and H be a minimal square root of G such that pw We need to prove that there exists an i such that d G−u (x, x i ) ≥ 3.This holds if x = x j for some j ∈ {1, . . ., 5}.Note also that ux i / ∈ E H because d G−u (x i , x j ) ≥ 3. Then for each i there exists v i such that x i v i ∈ E H and v i u ∈ E H .If i = j, then v i = v j , otherwise x i and x j would be adjacent in G.Moreover, v i v j / ∈ E H , otherwise d G−u (x i , x j ) = 2. Without loss of generality assume that v 1 , . . ., v 5 appear in this order in the path decomposition of H.This implies the existence of the bags {v 2 , x 2 , u}, {v 3 , x 3 , u} and {v 4 , x 4 , u} in the path decomposition of H. Consider the bags containing x.
If x appears before v 2 , consider the distance between x and x 4 .If the shortest path between x and x 4 in G − u contains x 2 or x 3 , then d G−u (x, x 4 ) ≥ d G−u (x, x 3 ) ≥ 3.If it does not contain x 2 and x 3 , then it must contain either v 2 , v 3 or another neighbor of u that appeared previously in the path decomposition and has no common neighbor with x 4 in H.However, If x appears between {v 2 , x 2 , u} and {v 3 , x 3 , u}, consider d G−u (x, x 5 ).By the same argument we obtain that d G−u (x, x 5 ) ≥ 3, because of the existence of bags {v 3 , x 3 , u} and {v 4 , x 4 , u}.The other cases follow by symmetry.

Given a vertex
by Observation 5, there exists a vertex v that is adjacent to at least one of u 1 and u 2 in H, but is not adjacent to u. Assume v is adjacent to u 1 .This implies v ∈ B u .Moreover, as u 1 u 2 ∈ E H , we have vu 2 ∈ E G .In Lemma 27.There exists a constant c 4 that depends neither on G nor on H such that pw(G H ) ≤ c 4 .
Proof.Let H be a minimal square root of G. Let U be the set of vertices of H such that d H (u) ≥ c 2 For each u ∈ U , we do the following.Consider the bags B 1 , . . ., B t in the path decomposition of H containing u and its neighbors.Starting from B 1 , we pick the first bag where a new neighbor of u appears.Let B i be such a bag.As B i contains at least one vertex that is not contained in B i−1 , we have |B i ∩ B i−1 | ≤ 2 and we already know that u ∈ B i ∩B i−1 .In the bags B 1 , . . .B i−1 , we replace u by u 1 .We create a new bag between B i−1 and B i containing u 1 , u 2 and (B i ∩ B i−1 ) \ {u}.In the bags B i , . . ., B t , we replace u by u 2 .In general, for every bag B k found containing a new neighbor of u we do the following: 1. Create a new bag between B k−1 and B k containing u j+1 and the vertices of B k−1 ∩ B k (note that u j ∈ B k−1 ∩ B k ). 2. In the bags B k , . . ., B t , replace u j by u j+1 .3. In H, add the edge between u j and u j+1 and an edge between u j+1 and the new found neighbor of u.
Let Ĥ be the graph obtained from H by the previous procedure.Note that H is a contraction of Ĥ, as H can be obtained by contracting the edges of the paths created for each vertex of U .Since we construct a path decomposition for Ĥ with the same width as the one we had for H, we have pw( Ĥ) ≤ 2. We claim that ∆( Ĥ) is bounded.If v ∈ V H \ U , then v has bounded degree in H and, in each step of the above procedure, the degree of v is maintained.The vertices u i created for each vertex of U have degree bounded by three.Thus the graph Ĥ has indeed bounded degree.
We claim that G H is a minor of Ĥc3+1 .Let Ĝ be obtained from Ĥc3+1 by the contraction of the paths created for each vertex of U .We can now assume that V Ĝ = V G H .We now show that G H is a subgraph of Ĝ.
Every edge of G H that belongs to E H is also an edge of Ĥc3+1 .Let xy ∈ E G H be such that xy / ∈ E H .As H is a square root of G, there exists u ∈ V G H such that xu, yu ∈ E H . Denote by X and Y respectively the sets of vertices of Ĥ that were contracted to x and y.If u / ∈ U , by the construction of Ĥ, there are x ∈ X and y ∈ Y such that x u, y u ∈ E Ĥ and therefore x y ∈ Ĥc3+1 and xy ∈ E Ĝ.If u ∈ U , there exists a path u i . . .u j in Ĥ, x ∈ X and y ∈ Y such that u i x ∈ E Ĥ and u j y ∈ E Ĥ .Since xy ∈ E G H and u ∈ U , we know that x, y ∈ X v for some v, otherwise we would have deleted this edge in the construction of G H .As the number of bags containing u and vertices of X v is bounded by c 3 by Lemma 26, the length of the path u i . . .u j is at most c 3 .This implies that d Ĥ (x , y ) ≤ c 3 +1 and hence x y ∈ E Ĥc 3 +1 , which implies xy ∈ E Ĝ.
Since G H is a subgraph of Ĝ and Ĝ is a contraction of Ĥc3+1 , we conclude that G H is a minor of Ĥc3+1 .Since G H is a minor of Ĥc3+1 , pw(G ) ≤ pw( Ĥc3+1 ).As Ĥ has pathwidth at most 2, pw( Ĥ) ≤ 2. Since Ĥ has bounded degree, by Observation 3, we obtain a constant c 4 such that pw(G H ) ≤ c 4 .

The Algorithm
Let G be the input graph.It is sufficient to solve Root of Pathwidth ≤ 2 for connected graphs.Hence, we assume that G is connected and has n ≥ 2 vertices.
First, we preprocess G using Lemma 19 to reduce the number of true twins that a given vertex of V G might have.To do so, we exhaustively apply the following rule, which is safe by Lemma 20.
Twin reduction.If G has a set X of true twins of size at least c 1 + 1, then delete an arbitrary u ∈ X from G. For simplicity, we call the graph obtained by exhaustive application of the Twin reduction rule G again.
In the next stage of our algorithm we label some edges of G red or blue in such a way that the edges labeled red are included in every minimal square root of pathwidth at most 2 and the blue edges are not included in any minimal square root of pathwidth at most 2. We denote by R the set of red edges and by B the set of blue edges.We also construct a set of vertices U of G such that for every u ∈ U , the edges incident to u are labeled red or blue.-Is H-Square Root polynomial-time solvable for every class H of graphs of bounded pathwidth?-Is H-Square Root polynomial-time solvable if H is the class of planar graphs?

Fig. 2 .
Fig. 2. The case when v1, v2, v3 are in the same component of H − u.
then return a no-answer and stop.Lemmas 10 and 11 imply the following claim.Lemma 15.If G has an outerplanar root, then Labeling does not stop in Step (v), and if (i) If xy / ∈ E G , then return a no-answer and stop.(ii) If for x and y, there is no v ∈ N G (u) such that vu ∈ B and x, y ∈ N G (v), then include xy in S. (iii) If R ∩ S = ∅, then return a no-answer and stop.Combining Lemmas 15 and 5, we obtain the following claim.Lemma 16.If G has an outerplanar root, then Finding irrelevant edges does not stop in Steps (i) and (iii), and if H is a minimal outerplanar root of G, then S ∩ E H = ∅.Assume that we did not stop during the execution of Finding irrelevant edges.Let G = G − S. We show the following.Lemma 17.The graph G has an outerplanar root if and only if there is a

Theorem 2 .
Root of Pathwidth ≤ 2 can be solved in time O(n 6 ), where n is the number of vertices of the input graph.

Lemma 20 .
Let W be a set of true twins in G such that |W | ≥ c 1 + 1 and let u ∈ W . Then G has a square root H such that pw(H) ≤ 2 if and only if G = G − u has a square root H such that pw(H ) ≤ 2.
Labeling.Set U = ∅, R = ∅ and B = ∅.For each u ∈ V G such that there are five distinct vertices in N G (u) that are at distance at least 3 from each other in G − u do the following:(i) set U = U ∪ {u}, (ii) set B = {ux ∈ E G | there is 1 ≤ i ≤ 5 s.t.dist G−u (x, v i ) ≥ 3}, (iii) set R = {ux | x ∈ N G (u)} \ B , (iv) set R = R ∪ R and B = B ∪ B , (v) if R ∩ B = ∅,then return a no-answer and stop.Lemmas 23 and 24 imply the following claim.Lemma 28.If G has a square root of pathwidth at most 2, then Labeling does not stop in step(v).Moreover, R ⊆ E H , B ∩ E H = ∅ and every vertex u ∈ V G with d H (u) ≥ c 2 is included in U .Next, we find the set of edges xy with xu, yu ∈ R for some u in U that are not an edge in any square root of pathwidth at most 2. Finding irrelevant edges.Set S = ∅.For each u ∈ U and each pair of distinct x, y ∈ N G (u) such that ux, uy ∈ R and xy ∈ E G do the following.(i) If there is no v ∈ N G (u) such that vu ∈ B and x, y ∈ N G (v), then include xy in S. (ii) If R ∩ S = ∅, then return a no-answer and stop.By Lemma 25, we obtain the following claim.Lemma 29.If G has a square root of pathwidth at most 2, then Finding irrelevant edges does not stop in step (ii), and if H is such a square root of G, then S ∩ E H = ∅.
Then xu, yu / ∈ E H for any square root H of G. Proof.Suppose that H is a square root of G. To obtain a contradiction, assume that ux ∈ E H .If uy ∈ E H , then xy ∈ E G contradicting the condition that dist G−u (x, y) ≥ 3. Hence, uy / ∈ E H .Because uy ∈ E G , there are uz, zy ∈ E H .If y = x, then xy ∈ E G ; a contradiction.If y = x, then xz ∈ E G and xzy is a path in G − u of length 2 and again we obtain a contradiction with the condition dist G−u (x, y) ≥ 3.
Suppose zv ∈ E H and zu / ∈ E H .As d H (z, x 1 ) ≤ 2, z is adjacent to x 1 in G, meaning that z must also be adjacent to x 16 in G.If zx 16 ∈ E H , then the bag {v, z, u} appears between bags B 1 and the bag containing x 16 and z.Then either v or z appear in at least five bags of B .If zx 16 / ∈ E H , let zyx 16 be a path of length two in H. Since p ≥ 12 and there must exist a bag containing x 16 and y, and thus one of v, z or y appear in at least five bags of B .