Deleting vertices to graphs of bounded genus

We show that a problem of deleting a minimum number of vertices from a graph to obtain a graph embeddable on a surface of a given Euler genus is solvable in time $2^{C_g \cdot k^2 \log k} n^{O(1)}$, where $k$ is the size of the deletion set, $C_g$ is a constant depending on the Euler genus $g$ of the target surface, and $n$ is the size of the input graph. On the way to this result, we develop an algorithm solving the problem in question in time $2^{O((t+g) \log (t+g))} n$, given a tree decomposition of the input graph of width $t$. The results generalize previous algorithms for the surface being a sphere by Marx and Schlotter [Algorithmica 2012], Kawarabayashi [FOCS 2009], and Jansen, Lokshtanov, and Saurabh [SODA 2014].


Introduction
In recent years, a significant effort has been put into the study of parameterized complexity of recognizing near-planar graphs [10,6,5], that is, graphs that become planar after deleting a small number of vertices. Since, by the classic result of Lewis and Yannakakis [9], the decision version of the problem is NP-hard, it is natural to look for fixed-parameter algorithms with various parameters.
The parameter of the size of the deletion set naturally comes from the supposed applications: a number of efficient algorithms for planar graphs generalize well to near-planar graphs, if one supply them with the deletion set. Formally, we define the problem Planar Vertex Deletion as follows: given a graph G and an integer k, decide, if one can delete at most k vertices from G to obtain a planar graph.
Clearly, for a fixed integer k, the yes-instances to Planar Vertex Deletion form a minor-closed graph class. Consequently, from the Graph Minors theory we obtain a nonuniform fixed-parameter algorithm for Planar Vertex Deletion (cf. [1,Section 6]).
Marx and Schlotter [10] showed an explicit, uniform fixed-parameter algorithm by a typical irrelevant vertex approach. First, they observe that the formulation of the problem as hitting all models of the forbidden minors for planar graphs (i.e., K 5 and K 3,3 ) leads to a fixed-parameter algorithm on bounded treewidth graphs by relatively standard techniques. Second, it is quite easy to believe (but quite technical to formally prove) that a middle part of a large, flat (planar), and grid-like subgraph of the input graph will never be part of an optimal deletion set, and can be removed without changing the answer to the problem. The combination of the excluded grid theorem and the technique of iterative compression gives here a winwin approach: if the treewidth of the graph is not sufficiently bounded, an irrelevant part can be uncovered and removed.
There are two sources of potential inefficiencies in the approach of Marx and Schlotter. First, the routine for graphs of bounded treewidth that finds a minimum set hitting all forbidden minor models work in time double-exponential in the treewidth bound. Since the treewidth bound needs to be significantly larger than the size of the deletion set for the irrelevant vertex argument to work, we obtain at least a doubleexponential dependency on the parameter. Second, the technique of iterative compression, at least applied in a straightforward manner, gives at least quadratic dependency on the input size.
Later, Kawarabayashi [6] showed a fixed-parameter algorithm with linear dependency on the input size. Finally, Jansen, Lokshtanov, and Saurabh [5] showed an algorithm with running time 2 O(k log k) n, that is, with nearly single-exponential dependency on the parameter and linear dependency on the input size.
On high level, the work of [5] follows the approach of Marx and Schlotter, but improves upon both components. First, they show that a routine that explicitly constructs partial embeddings of graphs of bounded treewidth solves the problem in question in time 2 O(t log t) n, given a tree decomposition of width t. Second, they show arguments in the spirit of the aforementioned irrelevant vertex rule that reduce the graph to treewidth linearly bounded in the size of the solution (deletion set). Third, they apply a more involved iterative compression approach that in one step compresses the graph by a multiplicative factor, yielding a linear dependency on the input size.
A simple reduction from the Vertex Cover problem (replace every edge uv with a K 5 with vertices u, v, and 3 new vertices) shows that, unless the Exponential Time Hypothesis (ETH) [4] fails, the dependency on the parameter k needs to be 2 Ω(k) for any parameterized algorithm for Planar Vertex Deletion.
Although it is open whether Planar Vertex Deletion can be solved in 2 o(k log k) n O(1) time, we note that a lower bound by the second author [12] asserts that, unless the ETH fails, the bounded treewidth subroutine requires dependency 2 Ω(t log t) on the treewidth of the graph. This implies that a hypothetical algorithm that solves Planar Vertex Deletion in 2 o(k log k) n O(1) time needs to follow significantly different approach than the one we know currently.
In the light of the aforementioned developments, in this paper, we initiate the study of the Genus Vertex Deletion: given a graph G and integers g and k, decide, if one can delete at most k vertices from G to obtain a graph embeddable on a surface of Euler genus at most g.
Our main result is the following: Theorem 1.1. Genus Vertex Deletion can be solved in time 2 Cgk 2 log k n O(1) , where C g is a constant depending on g only.
In the proof of Theorem 1.1, we follow the general approach of Marx and Schlotter [10]. Our main technical contribution is the generalization of the bounded treewidth subroutine of [5] to the bounded genus case.
Theorem 1.2. Given a Genus Vertex Deletion instance (G, g, k) with |V (G)| = n, and a tree decomposition of G of width t, one can solve the Genus Vertex Deletion problem on (G, g, k) in time 2 O((t+g) log(t+g)) n.
The proof of Theorem 1.2 follows the same principle as the corresponding routine of [5] -building partial embeddings for graphs with small boundaries -but requires significant technical hurdle to be presented formally and in full detail.
The task of the algorithm of Theorem 1.2 can be also seen as a generalization of an algorithm that computes the Euler genus in graphs of bounded treewidth: by substituting k = 0 we obtain an algorithm with running time 2 O((t+g) log(t+g)) n that checks if the input graph is embeddable on a surface of Euler genus at most g. Such a result is not new: a bounded treewidth routine is also part of the current algorithms that compute embeddings in linear time [11,7]. In particular, the work of Kawarabayashi, Mohar, and Reed [7] claims an algorithm with running time f (t) · n for some function f (i.e., without the exponential dependency on g). However, the work [7] is an extended abstract from FOCS 2008 that, to the best of our knowledge, never substantiated in a full version, and we were unable to reproduce the details of this algorithm from the description in [7].
For the second part, namely the irrelevant vertex argument, we generalize the arguments of Marx and Schlotter [10]: Theorem 1.3. For every integer g there exists a constant C g such that the following holds. Given a graph G, an integer k, and a set M ⊆ V (G) such that G − M is embeddable into a surface of genus at most g, one can in time C g n O(1) find one of the following: 2. a vertex w ∈ V (G) such that every solution to the Genus Vertex Deletion instance (G, g, k) contains w; or 3. a vertex v ∈ V (G) such that (G, g, k) is a yes-instance to Genus Vertex Deletion if and only if (G − {v}, g, k) is.
Theorem 1.1 follows now from Theorems 1.2 and 1.3 in a standard manner. By a standard application of the irrelevant vertex technique (cf. [1,Section 4], we can assume that, apart from the input Genus Vertex Deletion instance (G, g, k), we are additionally given a set M ⊆ V (G) of size k + 1 such that G − M is embeddable on a surface of Euler genus at most g (i.e., M is a solution of slightly too large size), at the cost of an additional O(n) factor in the running time bound. We iteratively apply the algorithm of Theorem 1.3 to (G, g, k) and M : if a vertex w or v is returned, we delete it and restart (decreasing the parameter k by one in case of a vertex w); if a tree decomposition is returned, we solve the Genus Vertex Deletion problem with the algorithm of Theorem 1.2.
Since |M | = k + 1, the algorithm of Theorem 1.2 is applied to a tree decomposition of width of the order of C g k 2 , yielding the bound promised in Theorem 1.1.
While the lower bound of [12] shows that the bounded-treewidth routine of Theorem 1.2 has optimal running time (assuming ETH), we conjecture that the running time bound of Theorem 1.1 is not optimal, and can be improved similarly as it was in the planar case [5]. For this reason, we do not optimize the parameter dependency in Theorem 1.3, favouring the clarity of the arguments. In other words, we view our contribution as Theorem 1.2 being the main technical merit, while Theorem 1.3 and the resulting Theorem 1.1 being an example application.
The paper is organized as follows: after introducing notation for permutations and tree decompositions in Section 2, we discuss combinatorial embeddings in Section 3. Theorem 1.2 is proved in Section 4, and Theorem 1.3 is proved in Section 5.

Permutations, involutions, cycles
For a nonnegative integer t, we denote [t] = {1, 2, . . . , t}. The group of all permutations of a set U is denoted by Sym(U ). Given a set of permutations S of a set U , by S we denote the subgroup of Sym(U ) generated by S. Given a subgroup Γ of the group of Sym(U ), by orb(Γ) we denote the family of orbits of Γ. For a permutation σ, orb(σ) is a shorthand for orb( σ ); this also allows us to speak about orbits of a single permutation. An orbit is trivial if it consists of a single element.
A permutation σ is an involution if σ(σ(i)) = i for every i ∈ domain(σ) and is fixed-point free if σ(i) = i for every i ∈ domain(σ). Note that a permutation is a fixed-point free involution if and only if every its orbit is of size exactly two.
A permutation σ is a cycle permutation if it has exactly one nontrivial orbit; note that σ needs to act cyclically on this orbit. A cycle is an unordered pair consisting of a cycle permutation and its inverse.
We will need the operation of restricting a cycle permutation σ to a subset A of the elements of the nontrival orbit v of σ: the result is a permutation σ A , where σ A (e) = e for every e / ∈ A while for every e ∈ A we have σ A (e) = σ k (e) where k is the minimum positive integer with σ k (e) ∈ A. In other words, we shorten the nontrivial orbit v by crossing out the elements not belonging to A. Note that if |A| ≥ 2, then σ A is also a cycle permutation, while for |A| ≤ 1 we have σ A being an identity. The definition of restricting naturally extends to cycles by restricting both components.
For a sequence P of elements of some set, byP we denote its reverse. A subsequence of a cycle is a sequence consisting of consecutive elements of the nontrivial orbit of the cycle.
The above order is cyclic: |v| is always even, and if |v| = 2k, then (β • α) k (e) = e. To fix notation, let us define a cycle permutation o α,β e of U as follows: Note that o α,β e is a cycle permutation whose nontrivial orbit is v. Furthermore, while its definition formally depends on the choice of e and the order of α and β, different choices of e ∈ v and a potential swap of the roles of α and β lead either to o α,β e or its inverse. The definition of a cycle is suited to accommodate that: For the cycle permutation o α,β e , its cycle is denoted asô α,β e . By the previous argumentation, the cycle does not depend on the order of α and β, nor of the choice of the element e within the same orbit.
Letσ 1 andσ 2 be two cycles of disjoint sets U 1 and U 2 , with nontrivial orbits v 1 and v 2 . A merge of σ 1 andσ 2 is a cycleσ of U := U 1 ∪ U 2 , whose nontrivial orbit v consists of exactly elements of v 1 ∪ v 2 . Furthermore, for some choice of cycle permutations σ 1 ∈σ 1 , σ 2 ∈σ 2 , σ ∈σ, for every i = 1, 2 and e ∈ v i , if k is the minimum positive integer for which σ k (e) ∈ v i , then σ k (e) = σ i (e). In other words, if we restrict the cycle of the nontrivial orbit ofσ to the elements of U i only, we obtain the cyclic order of the nontrivial orbit ofσ i .

Tree decompositions
Given a graph G, a tree decomposition of G is a pair (T, β) where T is a rooted tree and is a function β : V (T ) → 2 V (G) that assigns to every t ∈ V (T ) a bag β(t) ⊆ V (G) such that the following holds: • for every edge e ∈ E(G), there is a node t ∈ V (T ) with e ⊆ β(t); • for every vertex v ∈ V (G), the set {t ∈ V (T ) : v ∈ β(t)} is nonempty and induces a connected subgraph of T .
The width of a decomposition is the maximum size of a bag, minus one. For a tree decomposition (T, β) of a graph G, we define two auxiliary functions α and G ↓ . For a node t ∈ V (T ), • by α(t) ⊆ V (G) we denote the union of all bags of descendants of t (including t itself); • by G ↓ (t) we denote the graph G[α(t)] − E(G[β(t)]), that is, the graph induced by G ↓ (t) with the edges inside the bag β(t) removed.
For dynamic programming algorithms, it is often convenient to work with so-called nice tree decompositions, where the bag of the root is empty, and every node t ∈ V (T ) is of one of the following four types: leaf node has no children and its bag is empty; introduce node has one child t such that β(t) = β(t ) ∪ {v} for some vertex v / ∈ β(t ); forget node has one child t such that β(t) = β(t ) \ {v} for some vertex v ∈ β(t ); join node has two children t 1 and t 2 with β(t) = β(t 1 ) = β(t 2 ).
It is well-known (see, e.g., [1,8]) that, in polynomial time, one can turn any tree decomposition into an equivalent nice one without increasing its width.

Graph and hypergraph embeddings
We start with a clean but abstract notion of a hypergraph embedding, and then we restrict ourselves only to graph embeddings.
Definition 3.1 (hypergraph embedding). A hypergraph embedding is a tuple (F, θ, σ, φ), where F is a finite set, whose elements are called flags, and θ, σ, and φ are three fixed-point free involutions of the set F.
Given a hypergraph embedding E = (F, θ, σ, φ), we use the notation F(E) := F etc. Note that in any hypergraph embedding, since θ, σ, and φ are fixed-point free involutions, the number of flags needs to be even. Note that, as all three permutations of E are fixed-point free involutions, every vertex, edge, or a face of E can be identified with a cycle, whose nontrivial orbit is the vertex/edge/face in question.
Given a hypergraph embedding E = (F, θ, σ, φ), a size-k edge, vertex, or face is an orbit of Edges E , Verts E , or Faces E that consists of k flags. Note that k is always a positive even integer in this context. Also, observe that a size-2 edge corresponds to two equal orbits or θ and σ, a size-2 vertex corresponds to two equal orbits of σ and φ, while a size-2 face corresponds to two equal orbits of θ and φ.
We now define the genus of an embedding. Definition 3.3 (genus of a hypergraph embedding). Given a hypergraph embedding E = (F, θ, σ, φ), its genus is defined aŝ Since in any hypergraph embedding the number of flags is even, the genus of a hypergraph embedding is always an integer.
In a graph embedding, every edge consists of four flags. In other words, a hypergraph embedding E = (F, θ, σ, φ) is a graph embedding if no two orbits of θ and σ coincide, but the involutions θ and σ commute.
Observe that the formula for genus simplifies in case of a graph embedding.
is an embedding, then its genus equalŝ From this point, we use only graph embeddings in this work, and call them simply embeddings. If two objects (face, edge, vertex) share a flag, we say that these objects are incident. Note that an object with k flags can be incident to at most k/2 objects of each of the other types (e.g., a size-k vertex can be incident to at most k/2 edges and k/2 faces). In particular, in an embedding, edge can be incident to one or two faces and one or two vertices. An edge incident with only one vertex is a loop. Let us now relate the aforementioned definition of a (combinatorial) embedding with the natural intuition. Let G be a graph, embedded on a surface. We visualize every edge as a (thin, and possibly bend) rectangle, with a flag attached at every corner of the rectangle (see Figure 1). The involution θ pairs up flags on an edge that lie on the same side. The involution σ pairs up flags on an edge that lie at the same endpoint. Finally, the involution φ pairs up neighboring flags of consecutive edges around a vertex. In this manner, an orbit of Verts E = σ, φ yields a cyclic order of flags around a vertex, an orbit of Edges E = θ, σ yields a cyclic order of the four flags of an edge, while an orbit of Faces E = θ, φ yields a cyclic order of flags around a face. The formula (2) corresponds to the standard notion of an Euler genus of an embedding.

Basic operations on embeddings
We will need an operation of deleting an edge, and a reverse operation of drawing a new edge.

Deleting an edge
We start with the former. Let E = (F, θ, σ, φ) be an embedding and let e be an edge of E with flags We define an embedding E − e, the result of deletion of the edge e from E, in the following manner.
First, we disconnect the edge e from the rest of the embedding. For this, we modify φ so that {x, x } and {y, y } become its orbits: If {x, x } is not already an orbit of φ, we set a = φ(x) and a = φ(x ), and we replace {x, a} and {x , a } with {x, x } and {a, a }. Next, if {y, y } is not already an orbit of φ, we set b = φ(y), b = φ(y ), and we replace {y, b} and {y , b } with {y, y } and {b.b }. As the third and final step, we delete the flags of e and the corresponding orbits of all three involutions.
Note that the first two steps cannot be conveyed in parallel because φ(y) and φ(y ) might be altered during the first step. However, a direct check shows that {x, x } and {y, y } both become orbits of φ and that φ keeps being an involution. What is more, the order of the first two steps (i.e., the arbitrary decision of processing {x, x } prior to {y, y }) is irrelevant and edge deletion results in deleting the flags of e from the cycles corresponding to the vertices incident with e. This interpretation supports the following observation. Next, we describe how genus changes subject to edge deletion. Lemma 3.7. Let e be an edge in the embedding E, and let E 0 = E − e. Then the genus of E 0 is not larger than the genus of E. Furthermore, if e is incident to two faces or to a size-2 vertex, then the genera of E 0 and E are equal.
For vertices, recall that the operation of deleting an edge almost preserves the set of vertices: every vertex v 0 of E 0 originates from a vertex v of E by deleting the flags of e from the cycle of v. Thus, |orb(Verts E )| − |orb(Verts E0 )| equals the number of vertices of E that have all flags contained in e. There may be 0, 1, or 2 of them. Furthermore, if e is incident to two distinct faces, there are no such vertices, unless e is a loop at a vertex v incident only to e; in this case, e is incident to two faces of size 2, and its set of flags is a whole connected component of E.
For faces, consider first the case when e is incident to two faces, f 1 and f 2 , and assume that x i , y i lie on f i for i = 1, 2. Then, if the cycle of f i is x i , y i , P i for some sequence of flags P i , then the deletion of e replaces the faces f 1 and f 2 with one face with cycle P 1P2 , whereP 2 is the sequence P 2 reversed. Consequently, |orb(Faces E )| − |orb(Faces E0 )| = 1 in this case.
Consider now a case when e is incident to one face f . If the cycle of f is x 1 , y 1 , P 1 , x 2 , y 2 , P 2 for some sequences of flags P 1 and P 2 , then the deletion of e replaces f with a face with a cycle P 1P2 . If the cycle of f is x 1 , y 1 , P 1 , y 2 , x 2 , P 2 for some P 1 , P 2 , then the deletion of e replaces f with two faces with cycles P 1 and P 2 , respectively. Consequently, in this case we have |orb( For connected components, note that |orb(cc E )| − |orb(cc E0 )| ∈ {−1, 0, 1}: either e connects two distinct vertices that land in different connected components of E 0 , or the set of connected components essentially does not change (one connected component loses the flags of e) or e is a whole connected component and it disappears in E 0 .
Let us now wrap up the argument. If the set of flags of e is a whole connected component, then |orb(cc E )| − |orb(cc E0 )| = 1. This may happen if e is a loop at a vertex incident only to e, or if e connects two vertices incident only to e. In the first case, let k ∈ {1, 2} be the number of faces e is incident with. We have In particular, the genera of E and E 0 are equal if e is incident to two faces.
In the second case, when e connects two size-2 vertices, e is incident with one face with the same set of flags. Thus Now consider a case when e is incident to two faces, but is not a whole connected component. Then, at least one of this faces is of size larger than 2, say f 1 with cycle x 1 , y 1 , P 1 . Then, P 1 remains in E 0 as a sequence of flags, where every two consecutive flags form an orbit either of φ or of θ. Consequently, the flags of the vertices incident with e remain in the same vertices and in the same connected component, as P 1 connects the first and the last flags of P 1 . We infer that in this case we have: Consequently,ĝ E =ĝ E0 . Note that at this point we have concluded the proof thatĝ E =ĝ E0 if e is incident to two faces.
Consider now a case when e is incident to one face, and there exists its incident vertex v with the set of flags contained in e. As we have already excluded the case when the flags of e is a whole connected component, e is incident with two vertices v and v , and the flags of v are not contained in e. Furthermore, v is of size 2, say v consists of flags y 1 and y 2 . Then, the cycle of the face incident with e is x 1 , y 1 , y 2 , x 2 , P for some sequence of flags P . Consequently, We infer thatĝ E =ĝ E0 . Note that at this point we have concluded the proof thatĝ E =ĝ E0 if e is incident to a size-2 vertex.
Assume now that e is incident to one face, and every vertex incident with v has its set of flags not contained in e. Let f be the face incident with e. If the cycle of f is x 1 , y 1 , P 1 , x 2 , y 2 , P 2 , then the resulting face with cycle P 1P2 provides connectivity in E 0 between the (remainings of) vertices incident with e. Consequently, In this case In the last case, if the cycle of f is x 1 , y 1 , P 1 , y 2 , x 2 , P 2 , we have A direct corollary of Lemma 3.7 is the following.
Corollary 3.8. The genus of an embedding is always nonnegative.
Proof. Observe that any embedding can be turned into an empty embedding (i.e., one with no flags) by successive edge deletions. Since edge deletion cannot increase the genus (Lemma 3.7), and the empty embedding has genus zero, the lemma follows.

Drawing a new edge
Let us now define a reverse operation to edge deletion. Before, let us introduce a notion of position , φ(σ(φ(y)))) otherwise. It is easy to observe that defining the process of deletion of e, we set a and b so that (a, b) = p E (x). This lets us use p E (x) to undo the deletion. We often do not want to specify the flags of the new edge. In this case, we write a = ⊥ instead of a = x , a = instead of a = y, a = instead of a = y , and b = ⊥ instead of b = y . Let E = (F, θ, σ, φ) be an embedding, and let a ∈ F ∪ {⊥, , } and b ∈ F ∪ {⊥}. By drawing a new edge (x, y, y , x ) at (a, b) we mean the following operation, resulting in an embedding E 0 . First, we add new flags {x, y, y , x } to F and we set {x, x } and {y, y } to be new orbits of σ and φ, and setting {x, y} and {x , y } to be two new orbits of θ. Next, we replace a = ⊥, a = , a = , and b = ⊥ with a = x , a = y, a = y , and b = y , respectively. Finally, we adjust φ in the following two steps: If b = y , we define b = φ(b) and replace the orbits {y, y } and {b, b } with {y, b} and {y , b }. Then, if a = x , we define a = φ(a) and the orbits {x, x } and {a, a } with {x, a} and {x , a }.
We defined this operation so that it is clear that if e = (x, y, y , x ) is an edge of E, then one can retrieve E from E − e by drawing a new edge (x, y, y , x ) at p E (x). It is also easy to verify that drawing a new edge is a well defined and that if E 0 is obtained from E by drawing a new edge e, then E = E 0 − e.
Note that a = ⊥ and b = ⊥ both result in creating a new vertex (two new vertices if a = ⊥ and b = ⊥ hold simultaneously). Moreover, if a = ⊥, then x belongs to a new size-2 vertex (x, x ), while a = , then x belongs to a new size-2 face (x, y).
We identify one more special case of drawing a new edge. If a and b are distinct flags that lie on the same face f , and furthermore, the order of flags on the cycle of f is φ(a), a, P, b, φ(b), P for some (possibly empty) sequences of flags P and P , then we say that the new edge is drawn along the boundary of f . Observe that if this is the case, then the new edge e is incident to two faces: in the new embedding E 0 , the face f has been split into a face with cycle P, a, x, y, b and a face with cycle P , φ(b), y , x , φ(a). We explicitly allow here also the case b = φ(a); then the cycle of f is a, P, b for some sequence P , and the new embedding has new faces with cycles x , y and P, a, x, y, b.
Consequently, from Lemma 3.7 we immediately obtain the following.
Lemma 3.9. If E 0 is created from E by drawing a new edge, then the genus of E 0 is not smaller than the genus of E. Furthermore, the genera of E and E 0 are equal if the edge has been drawn along a face boundary or at (a, b) with a ∈ {⊥, }.

t-boundaried embeddings
is an embedding, t is a nonnegative integer, and L is an injective function from a subset of orb(Verts E ) to [t]. The elements of the domain of L are called labelled vertices, and the elements of [t] are labels.
A genus of a t-boundaried embedding (E, t, L) is the genus of the underlying embedding E.
The main motivation to introduce t-boundaried embeddings is to then merge them.
it is created by the following process. First, we take E to be a disjoint union of E 1 and E 2 , that is, we take: Then, for every label ∈ [t] that is contained in both the range of L 1 and L 2 , that is, there exists a cycle C i corresponding to the orbit L −1 i ( ) for i = 1, 2, we modify φ on the elements of C 1 and C 2 so that these elements form a single orbit of σ, φ whose cycle C is a merge of C 1 and C 2 . We assign this cycle the label in the assignment L.
A genus-minimum merge of E 1 and E 2 is a merge that minimizes its genus.
Note that, as we only modify φ in the merge operation, the set of edges of a merge is a union of the edges of the components. In particular, it follows that every edge of a merge consists of four flags, and thus it is indeed an embedding. Definition 3.12 (equivalence of t-boundaried embeddings). Two t-boundaried embeddings E 1 and E 2 are equivalent if for every t-boundaried embedding E, the genera of genus-minimum merges of E and E i for i = 1, 2 are equal.
By Observation 3.6, there is a natural correspondence between the vertices of E and E − e for every edge e of E. This correspondence allows us to extend the definition of edge deletion to t-boundaried embeddings: if E = (E, t, L) and e is an edge in E, then a t-boundaried embedding E − e is defined as (E − e, t, L 0 ), where L 0 is defined so that for every vertex v 0 of E − e, we take the corresponding vertex v of E, and copy its label to v 0 if v is labelled. Note that the range of L 0 may be a proper subset of the range of L if some labelled vertex in E has all its flags contained in the deleted edge e.
Furthermore, the characterization of vertex cycles in Observation 3.6 lets us relate edge deletion to merging.
Observation 3.13. Consider a merge E of t-boundaried embedding E 1 and E 2 . For every edge e of E 1 , we have that E − e is a merge of E 1 − e and E 2 .
Similarly, we can define the operation of drawing a new edge in a t-boundaried embedding; if a new vertex is created by this operation (due to a or b being equal to ⊥), we need to specify its label (or the fact that it is unlabelled). Thus, for each label unused in E, we add a special value ⊥ available for a and b, denoting the fact that the new vertex remains is labelled ; ordinary ⊥ denotes the fact that it is unlabelled. A counterpart of Observation 3.13 requires dealing with a special situation.
Observation 3.14. Consider a merge E of t-boundaried embedding E 1 and E 2 , and let E 1 be an embedding obtained from E 1 by drawing an edge at (a, b). Then a merge of E 1 and E 2 can be obtained from E by drawing an edge at (a , b ) , where a = a and b = b except for the following situation: if a = ⊥ (or b = ⊥ ) for a label used in E but not in E 1 , then a (resp. b ) is an arbitrary flag of E contained in a vertex with label .

Nice embeddings
We say that a vertex or a face is isolated if its set of flags is a whole connected component.  (F, θ, σ, φ) is nice if the following two conditions hold: 1. If an unlabelled vertex consists of less than 6 flags, then it is isolated.
2. If an edge e is incident to two faces, then for every face f incident with e, if we denote by x and y = θ(x) the two flags contained both in f and e, then there is a flag z ∈ f \ {x, y, φ(x), φ(y)} that is contained in a labelled vertex.
Our goal in this section is to show that any embedding can be turned into an equivalent nice one. The main motivation for such a cleaning step is that a nice embedding enjoys a good size bound due to the Euler formula-style estimations, presented in the next section.
Proof. Let E = (F, θ, σ, φ). We perform a discharging argument. The setup is as follows: • every labelled vertex receives a charge of 2; • every isolated vertex receives a charge of 1; • every isolated face receives a charge of 1; • every edge receives a charge of 5 6 . The total initial charge is at most 2t + 2|orb(orb(cc E ))| + 5 6 |orb(Edges E )|.
Then we move the charge according to the following rules: 1. Every labelled vertex that is incident to only one face, sends a charge of 1 to the face it is incident with.
2. Every edge that is incident only to labelled vertices, divides a charge of 2 3 equally among the faces it is incident with. In other words, every flag in such an edge sends a charge of 1 6 to the face it is contained in.
3. Every edge that is incident with two vertices, one labelled and one unlabelled, gives a charge of 1 3 to the unlabelled incident vertex, and divides the remaining charge of 1 2 equally between the faces it is incident with. In other words, in the first part every flag in such an edge contained in unlabelled vertex sends a charge of 1 6 to the vertex it is contained in. In the second part, every flag in such an edge sends a charge of 1 8 to the face it is contained in.
4. Every edge that is incident only to unlabelled vertices, divides the charge of 2 3 equally among the vertices it is incident with. In other words, every flag in such an edge sends a charge of 1 6 to the vertex it is contained in.
Clearly, every edge is left with non-negative charge (0 or 1 6 ). We now show that at the end of the process, every vertex and every face has charge of at least one.
First, let us consider a vertex v. If v is labelled or isolated, 1 out of its initial charge remained, and the claim is straightforward. Next, we assume that v is unlabelled and not isolated. By the first property of a nice embedding, v is of size at least 6. It received exactly 1 6 from each of its flags, i.e., at least 1 in total. Consider now a face f . We make case distinction depending on how many flags of f belong to labelled vertices and how these flags are located on the cycle corresponding to f .
No flags of f belong to a labelled vertex. Observe that every edge e incident with f is incident only with one face, as otherwise it would contradict the second property of a nice embedding. Consequently, f is isolated an it received an initial charge of 1. Along f there exist two nonconsecutive orbits of φ that are included in labelled vertices. Let {x, x } and {y, y } be these orbits. Since they are nonconsecutive, x, x , θ(x), θ(x ), y, y , θ(y), θ(y ) are eight pairwise distinct flags in f , each sending a charge of at least 1 8 to the face f . Note that the last three cases case cover the case of f having at least 4 flags contained in labelled vertices.
We have shown that there was enough charge so that every vertex and every face received a charge of at least one. Consequently, |orb(Faces E )| + |orb(Verts E )| ≤ 2t + 2|orb(cc E )| + 5 6 |orb(Edges E )|.

Making an embedding nice
Let E = (E, t, L) be a t-boundaried embedding with E = (F, θ, σ, φ). Our goal now is to obtain an equivalent nice embedding. To this end, we show that the following three operations lead to equivalent embeddings: 1. deleting an edge incident with an unlabelled size-2 vertex; 2. deleting an edge violating the last property of the definition of a nice embedding; 3. suppressing a size-4 unlabelled vertex that is not isolated.
We will henceforth call them simplifying operations.
Lemma 3.18 (deleting an edge incident to a size-2 unlabelled vertex). If e is an edge of E incident to an unlabelled vertex of size 2, then E − e and E are equivalent.
Proof. We consider merges E and E − e with an arbitrary t-boundaried embedding E 1 . First, let E M be a merge of E 1 and E. Observation 3.13 yields that E M − e is a merge of E − e and E 1 and Lemma 3.7 implies that its genus does not exceed the genus of E M . Consequently, the genus of a genus-minimum merge of E 1 and E − e is not larger than the genus of a genus-minimum merge of E 1 and E.
In the other direction, let E M be a merge of E − e and E 1 . Let e = (x, y, y , x ) where {x, x } is contained in an unlabelled size-2 vertex so that p E (x) is of the form (x , b). Consequently, E can be obtained from E − e by drawing a new edge e at (⊥, b) for some b. By Observation 3.14, a merge E M of E 1 and E can be obtained from E M by drawing a new edge at (a , b ). Since a = ⊥, we have a = ⊥, so the genera of E M and E M are equal due to Lemma 3.9. Consequently, the genus of a genus-minimum merge of E 1 and E is not larger than the genus of a genus-minimum merge of E 1 and E − e. This completes the proof of the lemma. Proof. Again, we consider merges of E and E − e with an arbitrary t-boundaried embedding E 1 . In one direction, the proof is the same as in the proof of the previous lemma: Observation 3.13 and Lemma 3.7 imply that the genus of a genus-minimum merge of E 1 and E − e is not larger than the genus of a genus-minimum merge of E 1 and E.
In the other direction, let E M be a merge of E 1 and E − e. We consider two cases depending on whether f is of size 2. If so, then p E(x) is of the form (y, b), so E can be obtained from E − e by drawing an new edge at ( , b) for some b. By Observation 3.14, a merge E M of E 1 and E can be obtained from E M by drawing a new edge at (a , b ). Since a = , we have a = , so the genera of E M and E M are equal due to Lemma 3.9.
Next, suppose that f contains a flag z / ∈ {x, y}. Since e is incident to 2 faces, we conclude that σ(x) and σ(y) do not belong to e, and E can be obtained from E − e by drawing a new edge at (a, b) for a = σ(x) and b = σ(y). By Observation 3.14, a merge E M of E and E 1 can be obtained from E M by drawing a new edge at (a, b). Let the cycle of f be x, a, P, b, y for some (possibly empty) sequence of flags P . By the assumptions of the lemma, every flag of P belongs to an unlabelled vertex. Consequently, in E M there exists a face f whose cycle contains consecutive flags a, P, b on its cycle, as no orbit of φ or θ on a, P, b has been altered This means that a new edge drawn at (a, b) is actually drawn at a face boundary. Hence, the genera of E M and E M are equal due to Lemma 3.9.
Consequently, the genus of a genus-minimum merge of E 1 and E is not larger than the genus of a genusminimum merge of E 1 and E − e, which concludes the proof of the lemma.
For the last basic operation, we need to formally define it. Let E = (E, t, L) be a t-boundaried embedding with an unlabelled size-4 vertex v that is not isolated. Since v is not isolated, v is incident with two edges e 1 and e 2 , and each e i is incident with v and a vertex v i = v. Note that it is possible that v 1 = v 2 .
Let x 1 and x 2 = φ(x 1 ) be two flags in v such that x i belongs to e i . Furthermore, let y i = θ(x i ); note that y i lies in e i . We delete all four flags of v, and replace the orbits of θ on e 1 and e 2 with {y 1 , y 2 } and {σ(y 1 ), σ(y 2 )}. Clearly, we have replaced e 1 and e 2 with a new edge with flags y 1 , y 2 , σ(y 1 ), σ(y 2 ). We now formally verify that the output embedding is an equivalent one. Lemma 3.20 (suppressing a size-4 unlabelled vertex that is not isolated). The operation of suppressing a size-4 unlabelled vertex leads to an equivalent embedding.
Proof. We interpret the suppressing operation as a sequence of one edge drawing and two edge deletions.
Observe that y 1 , x 1 , x 2 , y 2 are four distinct flags that lie on the same face f and, furthermore, they are consecutive in this order along the cycle of f . Let us draw a new edge e f along the boundary of f , at y 1 and y 2 , obtaining an embedding E f . Note that in E f there is a new face f with cycle y 1 , x 1 , x 2 , y 2 , z 2 , z 1 , where {z 1 , z 2 } is a new orbit of θ contained in the edge e f . Furthermore, the edge e f with face f fulfills the assumptions of Lemma 3.19, and its deletion from E f gives E. Consequently, E f and E are equivalent.
Then, we delete edges e 1 and e 2 from E f , obtaining an embedding E . Our goal is to show that such an operation leads to an equivalent embedding; note that if we rename the flags of e f to y 1 , y 2 , σ(y 1 ), σ(y 2 ) we obtain the output embedding of the suppressing operation. The proof is similar to that of Lemma 3.19, but without most of the special cases due to the existence of the edge e f . Let E 1 be an arbitrary t-boundaried embedding. By Observation 3.13 and Lemma 3.7 yields that the genus of a genus-minimum merge of E 1 and E is not larger than the genus of a genus-minimum merge of E 1 and E f .
For the other direction, let E M = (E M , t, L M ) be a merge of E 1 and E . Note that p E f (x 1 ) = (x 2 , z 1 ) and Hence, E f can be retrieved from E by drawing edge e 2 at (⊥, z 2 ) and then edge e 1 at (x 2 , z 1 ). By Observation 3.14, a merge E M of E f and E 1 can be retrieved from E M by drawing an edge e 2 at (⊥, z 2 ) and then e 1 at (x 2 , z 1 ). Lemma 3.9 yields that the first of these operations asserts that the genus remains unchanged. As for the second operation, we observe after drawing e 2 , we have that x 2 , y 2 , z 2 , z 1 is a fragment of face boundary and that e 1 is drawn along it. Hence, Lemma 3.9 also implies that the genera of E M and E M are equal. We infer that the genus of a genus-minimum merge of E 1 and E f is not larger than the genus of a genus-minimum merge of E 1 and E . This concludes the proof of the lemma.
Armed with the three basic operations, we are now ready to prove the following statement. Proof. Let E be a t-boundaried embedding. If E is nice, we can just return E. Otherwise, observe that any object that violates the niceness of E gives rise to an application of one of the simplifying operations. An edge violating the last property of a nice embedding can be deleted from E; the resulting embedding is equivalent due to Lemma 3.19. Similarly, if there exists an unlabelled size-2 vertex, then Lemma 3.18 allows us to safely delete the incident edge, and a size-4 unlabelled vertex that is not isolated can be also suppressed by Lemma 3.20. Finally, note that each execution of a simplifying operation strictly decreases the number of flags in the embedding. Consequently, in polynomial time we obtain an equivalent nice embedding.

Bounded treewidth graphs
In this section we prove Theorem 1.2. Without loss of generality, we can assume that the input tree decomposition (T, β) of the input graph G is a nice tree decomposition of width less than k, that is, every bag of (T, β) is of size at most k.
We first refine (T, β) as follows. First, with every node t we associate a graph G(t), initialized as G(t) := G ↓ (t). In the refinement process, we will maintain the invariant that at every node t, the graph G(t) is a subgraph of G[α(t)] and a supergraph of G ↓ (t); in particular, V (G(t)) = V (G ↓ (t)). Note that one needs only O(t 2 ) bits to store G(t) at every node t, as one needs only to store which edges of G[β(t)] belong to G(t).
For every forget node t we perform the following refinement process. Let t be the child of t, and let v be the forgotten vertex, i.e., {v} = β(t ) \ β(t). Let e 1 , e 2 , . . . , e be the edges incident with v that have their second endpoint in β(t); note that {e 1 , e 2 , . . . , e } are exactly the edges that are present in G ↓ (t) but are not present in G ↓ (t ). Our goal is to refine the edge tt of T by inserting a number of vertices on this edge so that the transition from G ↓ (t ) to G ↓ (t) is more smooth.
More precisely, we subdivide the edge tt times, inserting vertices t 1 , t 2 , . . . , t in this order, such that t 1 is adjacent with t, and t is adjacent with t . Furthermore, to every node t i add a second child s i that is a leaf of the tree T . The new node s i is of a new type, namely edge leaf : we set β(s i ) = β(t ), V (G(s i )) = β(t ), and E(G(s i )) = {e i }. The node t i is a join node with G(t i ) = G ↓ (t ) − {e 1 , e 2 , . . . , e i−1 }.
This completes the description of the tree decomposition refinement. By this step, we have obtained the following properties: at every introduce or forget node t with child t we have G(t) = G(t ), while at every join node t with children t 1 and t 2 we have E(G(t)) = E(G(t 1 )) E(G(t 2 )). Furthermore, note that we have introduced two nodes for every edge of G, giving O(nk) new nodes in total.
We compute a labelling function Λ : V (G) → [k] such that Λ is injective on every bag of (T, β); such a labelling Λ is straightforward to compute in a top-to-bottom fashion, using the fact that every bag of (T, β) is of size at most k.
With the refined tree decomposition, we perform a bottom-up dynamic programming algorithm. Fix a node t ∈ V (T ). For a subset A ⊆ α(t) and an embedding E of G(t)[A], we can naturally equip E with a structure of a k-boundaried embedding by assigning labels Λ| β(t) (which is an injective function). We will denote such a k-boundaried embedding at node t as bnd(t, E) At t, we maintain the following DP table. For every set X ⊆ β(t) and for every nice k-boundaried embedding E of genus at most g that uses only labels of Λ(β(t) \ X), we remember a value T[t, X, E] ∈ {0, 1, . . .} ∪ {+∞}. Intuitively, we would like the value T[t, X, E] to indicate the minimum size of a deletion set Y ⊆ α(t) \ β(t) such that G(t) − (X ∪ Y ) can be embedded equivalently with E. However, for sake of the formal argument, we strip the above intuition into only its essential parts, and define the following two properties that we maintain: (a good deletion set is represented in the table) for every set Y ⊆ α(t) \ β(t), every embedding E of G(t) − (X ∪ Y ), every k-boundaried embedding E 0 that uses only labels of Λ(β(t) \ X), and every merge E 0M of bnd(t, E) and E 0 , there exists a nice k-boundaried embedding E and a merge E M of E and E 0 such that T[t, X, E] ≤ |Y | and the genus of E M is not larger than the genus of E 0M .
The above invariants include only one inequality from the definition of equivalence: the one that is needed for the proof of the correctness of the algorithm. In particular, since the root node r has an empty bag, the minimum value of T[r, ∅, ·] at the root node is the size of the minimum solution to Genus Vertex Deletion on (G, g). Indeed, by the second invariant, an optimum solution Y * and the corresponding embedding E * has its corresponding entry E * when merged with an empty embedding E 0 (so that E 0M = bnd(r, E) = (E, k, ∅)), and we have |Y * | ≥ T[r, ∅, E * ]. In the other direction, the first invariant ensures that for every entry T[r, ∅, E] and again an empty embedding E 0 and the only possible merge E 0M = E, there exists a deletion set Y of size at most T[r, ∅, E] and an embedding E of G − Y such that bnd(r, E) has genus at most the genus of E 0M = E, which is at most g.
We now show how to compute the values T[t, X, E] in a bottom-to-up fashion. The computation is trivial at leaf nodes (empty bag, empty graph G(t)) and at edge leaf nodes (a single edge with distinct endpoints). Furthermore, observe that at introduce nodes, we just copy the corresponding entries in T, as the new vertex is isolated in G(t) and the notion of an embedding ignores isolated vertices. Thus, we are left with tackling forget and join nodes.
To this end, we define an operation of updating a cell T[t, X, E] with a value a: we set T[t, X, E] := max(a, T[t, X, E]). We say that the update was successful if the stored value changed.

Forget nodes
Let t be a forget node with child t and let v be the forgotten vertex. Note that, due to the refinement step, we have G(t ) = G(t). The only difference between the nodes t and t is that if we consider some embedding E of a subgraph of G(t), then bnd(t , E) assigns a label Λ(v) to the vertex v, while in bnd(t, E) the vertex v remains unlabelled. This is straightforward to implement in our DP tables. We start by setting all values T[t, X, E] to +∞. For every cell T[t , X, E] with v ∈ X, we update the cell T[t, X \ {v}, E] with value T[t , X, E] + 1: when v is deleted, the embedding does not change, but we need to account for the vertex v in the value of the cell. For every cell T[t , X, E ] with v / ∈ X, we create an embedding E from E by first forgetting the label of the vertex v (so it becomes an unlabelled one), and then by applying Lemma 3.21 to obtain an equivalent embedding. We update the cell We now formally verify that the entries for node t satisfy the required properties.
First property. Take a cell T[t, X, E] that is less than +∞, a k-boundaried embedding E 0 and a merge E 0M of E and E 0 . Let T[t , X , E ] be the last cell that caused an update in the value of T[t, X, E]. First, assume v ∈ X ; then X = X ∪ {v} and E = E. By the first property, applied inductively to the cell T[t , X , E], the embedding E 0 and the merge E 0M , we obtain a set Y of size at most T[t , X , E], an embedding E of G(t ) − (X ∪ Y ) and a merge E M of bnd(t , E ) and E 0 of genus at most the genus of Consequently, E is an embedding of G(t) − (X ∪ Y ), and together with Y and E M satisfies the requirements of the first property.
In the second case, we have v / ∈ X , and X = X . Let E • be the embedding E with the label of v dropped; recall that E is a result of application of Lemma 3.21 to the embedding E • . Since E • is equivalent to E, the genus-minimum merge E • M of E • and E 0 has genus not larger than the genus of E 0M . Since neither E • nor E 0 uses the label Λ(v), we can define E M to be E • M with additionally label Λ(v) assigned to the vertex v; note that this operation does not change the genus of the embedding. As E 0 does not use the label Λ(v), E M is a merge of E and E 0 . The first property, applied to the cell T[t , X , E ], E 0 , and the merge E M , yields existence of a set Y ⊆ α(t ) \ β(t ), an embedding E of G(t ) − (X ∪ Y ), and a merge E M of bnd(t , E) and E 0 of genus at most the genus of E M . Since G(t ) = G(t), X = X, and E 0 does not use the label Λ(v), E M is a merge of bnd(t, E) and E 0 . Furthermore, since the genus of E M is at most the genus of E 0M , the tuple (Y , E, E M ) fulfills the first property.
Second property. Take a set Y , E, E 0 , and E 0M as in the statement of the second property. If v ∈ Y , take Y = Y \ {v} and X = X ∪ {v}, and otherwise take Y = Y and X = X. In both cases, we have Since E 0 does not use the label Λ(v), E 0M is also a merge of bnd(t , E) and E 0 . By the second property for t , X , Y , E 0 , and E 0M , we obtain a k-boundaried embedding E and a merge E M of E and E 0 of genus at most the genus of E 0M such that T[t , X , E ] ≤ |Y |. While processing the cell T[t , X , E ] the algorithm attempts an update on a cell T[t, X, E] for E being a result of an application of Lemma 3.21 to the embedding E • being the embedding E with the label of v dropped. A direct check shows that in regardless of whether v belongs to Y or not, it follows that T[t, X, E] ≤ |Y |.
Let E • M be the embedding E M with the label Λ(v) dropped if present; note that the genera of E • M and E M are equal. Since the embedding E 0 does not use the label Λ(v), the merge E • M is a merge of E • and E 0 . By the equivalence of E • and E, the genus-minimum merge E M of E and E 0 is of genus at most the genus of E • M , which in turn is at most the genus of E 0M . Thus, E and E M fulfill the second property for Y , E, E 0 , and E 0M .
This finishes the description and the proof of correctness of the computations at forget nodes.

Join nodes
Let t be a join node with children t 1 and t 2 . Note that we have V (G(t 1 )) ∩ V (G(t 2 )) = β(t), V (G(t 1 )) ∪ V (G(t 2 )) = V (G(t)) and E(G(t)) = E(G(t 1 )) E(G(t 2 )). We iterate over every set X ⊆ β(t) and every pair of cells T[t 1 , X, E 1 ] and T[t 2 , X, E 2 ]. Note that both E 1 and E 2 are k-boundaried embeddings with labels on vertices of β(t) \ X. For every k-boundaried embedding E that is a merge of E 1 and E 2 , we use Lemma 3.21 to compute a nice embedding equivalent to E , and update T[t, X, E] with T[t 1 , X, We now formally verify that the entries for node t satisfy the required properties.
First property. Take a cell T[t, X, E] that is less than +∞, a k-boundaried embedding E 0 and a merge E 0M of E and E 0 . Let g 0 be the genus of E 0M . Assume the value of T[t, X, E] comes from considering cells 2 and E B M , obtaining a set Y 1 , an embedding E 1 , and a merge E M of bnd(t 1 , E 1 ) and E B 2 of genus at most g 0 . Since E B 2 is a merge of bnd(t 2 , E 2 ) and E 0 , if we delete the edges of E 0 from E M , we obtain an embedding E 12 that is a merge of bnd(t 1 , E 1 ) and bnd(t 2 , E 2 ). Let E be the embedding underlying Since the genus of E M is at most g 0 , the proof of the first property is finished.
Second property. Take a set Y , E, E 0 , and E 0M as in the statement of the second property, and let g 0 be the genus of E 0M . For i = 1, 2, take Y i = Y ∩ α(t i ) and E i to be the embedding E restricted to the edges of G(t i ) (i.e., with the edges of G(t 3−i ) deleted). Note that bnd(t, E) is a merge of bnd(t 1 , E 1 ) and bnd(t 2 , E 2 ).
First, let E A 1 be the embedding E 0M with the edges of E 2 deleted. Observe that E A 1 is a merge of bnd(t 1 , E 1 ) and E 0 , while E 0M is a merge of E A 1 and bnd(t 2 , E 2 ). By the second property, applied to t 2 , X, Y 2 , E 2 , E A 1 , and E 0M , we obtain a nice k-boundaried embedding E 2 and a merge E B M of E 2 and E A 1 of genus at most g 0 such that T[t 2 , X, E 2 ] ≤ |Y 2 |. Now, if we delete the edges of E 1 from E B M , we obtain an embedding E B 2 . Observe that E B 2 is a merge of E 0 and E 2 , while E B M is a merge of bnd(t 1 , E 1 ) and E B 2 . We apply the second property to t 1 , X, Y 1 , E 1 , E B 2 , and E B M , obtaining a nice k-boundaried embedding E 1 and a merge E M of E 1 and E B 2 of genus at most g 0 such that T[t 1 , X, Let E be the embedding E M with the edges of E 0 deleted. Since E M is a merge of E 1 and E B 2 , which in turn is a merge of E 2 and E 0 , we have that E is a merge of E 1 and E 2 and E M is a merge of E and E 0 . Consequently, the algorithm attempts an update on the cell T[t, X, E] with the value Since the genus of E M is at most g 0 , the pair E and E M fulfills the second property for Y , E, E 0 , and E 0M .

Summary
We have concluded description and correctness proofs of the operations at the nodes of the tree decomposition. At every node t, a straightforward implementation takes time polynomial in the number of entries T[t, X, E], which, by Corollary 3.17, is 2 O((k+g) log(k+g)) . This finishes the proof of Theorem 1.2.

Irrelevant vertex
In this section, we prove Theorem 1.3: Theorem 1.3. For every integer g there exists a constant C g such that the following holds. Given a graph G, an integer k, and a set M ⊆ V (G) such that G − M is embeddable into a surface of genus at most g, one can in time C g n O(1) find one of the following: 1. a tree decomposition of G of width at most C g |M | 1/2 k 3/2 ; 2. a vertex w ∈ V (G) such that every solution to the Genus Vertex Deletion instance (G, g, k) contains w; or 3. a vertex v ∈ V (G) such that (G, g, k) is a yes-instance to Genus Vertex Deletion if and only if The argumentation is heavily inspired by the corresponding planar case by Marx and Schlotter [10]. As in most irrelevant vertex arguments, we follow typical outline: 1. Run an approximation algorithm for treewidth and, in case it returns that the treewidth of the graph is larger than the required threshold, find a large grid minor. Here, the linear dependency on the grid size and treewidth in bounded genus graphs is known, and one can find the corresponding grid minor efficiently.
2. Show that a vertex w ∈ M that is connected to many places in the grid that are far apart needs to be included in every solution, exactly as it is in the planar case. In the absence of such a vertex, a large part of the grid minor is flat, that is, embeds planarly and does not have any internal connections to the modulator M .
3. Prove that a middle vertex of such a flat part is irrelevant. Here, the challenge is to argue that in every solution there exists an embedding of the remaining part that draws the flat part indeed in a flat manner.
We repeatedly use the following auxiliary result throughout this section: . Let Γ be a surface of Euler genus g and let C be a set of g + 1 disjoint circles in Γ. If Γ \ C has a component D 0 whose closure in Γ meets every circle in C, then at least one of the circles in C bounds a disc in Γ that is disjoint from D 0 .
Let G, k, g, and M be such as in the statement of Theorem 1.3. We start by computing an embedding E 0 of G − M into a surface of Euler genus at most g, using either the algorithm of Kawarabayashi, Mohar, and Reed [7] or the older algorithm of Mohar [11]. 1 This takes time C 1 g n for some constant C 1 g depending only on g.

Finding a large grid
We apply a constant-factor approximation algorithm for treewidth and largest excluded grid minor in graphs with a fixed excluded minor [2,Theorem 3.11]. The algorithm does not need to compute a near-embedding of G, as E 0 serves this purpose. Thus, the algorithm as described in [2,Theorem 3.11] runs in time C 2 g n O(1) for some constant C 2 g depending only on g, and is a C 3 g -approximation. If the resulting tree decomposition is of width at most C 4 g |M | 1/2 k 3/2 for some sufficiently large constant C 4 g , then we directly return it. Otherwise, by choosing the constant C 4 g appropriately, we get a grid minor of sidelength Θ(|M | 1/2 (k + g) 3/2 g 1/2 ). By standard arguments, we henceforth focus on the case when we get a wall W 0 of sidelength 0 as a subdivision in G − M , where 0 = Θ(|M | 1/2 (k + g) 3/2 g 1/2 ) can be chosen arbitrarily large; see Figure 2 for the definition of a wall.
In the wall W 0 , we identify g + 1 pairwise disjoint subwalls of sidelength 1 for every 1 = Θ( 0 / √ g) = Θ(|M | 1/2 (k + g) 3/2 ), leaving enough space between the subwalls so that the part of W 0 not contained in any of the subwalls is connected. By Lemma 5.1, for at least one of the identified subwalls, its surrounding cycle bounds a disc in the considered embedding of G − M . Consequently, at least one of the identified subwalls is planarly embedded in E 0 . We denote this subwall as W 1 and the part of G − M embedded in the disc separated by the surrounding cycle of W 1 by G 1 . In what follows, we mostly focus on G 1 and W 1 .

Filtering out the modulator neighbors
We now show that if a vertex w ∈ M is adjacent to many scattered vertices of G 1 , then it needs to be included in every solution. We start with constructing a canonical graph of Euler genus larger than g.
Lemma 5.2. For an integer > 1, let B be a graph defined as follows. We take disjoint copies of K − 5 (i.e., the five-vertex clique K 5 with an edge deleted), and denote by v i and w i the endpoints of the removed edge in the i-th copy. We introduce two further vertices v and w and make v adjacent to all vertices v i and w adjacent to all vertices w i . Then, the Euler genus of B is at least /2.
Proof. Consider an embedding of B into a surface Γ of Euler genus g. For i = 1, 2, . . . , , let γ i be the triangle in the i-copy of K − 5 that does not pass through v i or w i , treated as a closed curve on Γ. Since Γ has Euler genus g, by Lemma 5.1, at least − g of the curves γ i must be contractible.
Consider an index i for which γ i is contractible, and let V (γ i ) be the three vertices of G that lie on γ i . Since G − V (γ i ) is connected, γ i is a boundary of a face of the embedding of G. Augment the graph G by adding a new vertex x i inside this face, and connect it to the three vertices of V (γ i ).
In this manner, the i-th copy of K − 5 , together with the new vertex x i , forms a nonplanar graph (a supergraph of K 3,3 ). Consequently, we cannot perform this operation in parallel for more than g indices i. We infer that ≤ 2g, and the lemma is proven.
Recall that the boundary cycle of W 1 encloses a disc containing W 1 in the considered embedding E 0 of G − M , and G 1 is the part of the graph G − M that is enclosed by this boundary cycle. For a vertex v ∈ V (G 1 ) and an integer , the radius-ball B(v, ) around v is defined as follows: we take all faces f of W 1 (excluding the infinite face) that contain v either inside or on the boundary, mark all faces that lie in face-vertex distance (excluding traversal through the infinite face) at most from one of these faces f and put into B(v, ) all vertices of G 1 that are contained inside or on the boundary of marked faces.
For every w ∈ M , we create a set I(w) ⊆ V (G 1 ) as follows. We start with I(w) = ∅ and every vertex of V (G 1 ) unmarked. As long as there exists an unmarked neighbor v of w in G 1 , we insert v into I(w) and mark all vertices of B(v, 2 ) for 2 = 100(k + g + 1). We claim that if I(w) is too large, the vertex w needs to be deleted in any solution to Genus Vertex Deletion.

Middle vertex of a flat part is irrelevant
Let v be a vertex on the middle face of W 3 . We show that v is irrelevant, that is, it can be returned as the outcome of Theorem 1.3. Clearly, if (G, g, k) is a yes-instance, then so is (G − {v}, g, k). In the other direction, suppose that there exists S ⊆ V (G) \ {v} such that G − {v} − S admits an embedding E into a surface of Euler genus at most g. We would like to enhance this embedding so that it also accommodates v.
The sidelength 3 of W 3 is large enough to find in W 3 a subdivision of a circular wall W 4 of height h 4 = 5(k + g) + 9 and circumference 4 = min(3, k + 1) so that v is located inside the inner cycle of the wall; see Fig. 3 for the definition of a circular wall. Next, in W 4 we identify k + g + 2 rings (which are concentric circular walls of height 5 and circumference 4 ), separated by layers of height 1; see Fig. 3. Let R 0 be the family of identified rings.
For a ring R ∈ R 0 , we say that the central circle of R is the circle between the two middle layers of the ring, and the boundary circles are the circles separating R from the remainder of W 4 . A face of R in the embedding E 0 is small if it is not the outerface nor the face inside the innermost cycle, and central if it is incident to the central circle. The territory of R, denoted by T (R), is the subgraph of G that consists of R and everything that is drawn in the embedding E 0 in the small faces of R. Note that T (R) is a planar graph, and the subgraphs {T (R) : R ∈ R 0 } are vertex-disjoint.
Let R ⊆ R 0 be the family of these rings for which T (R) is disjoint with S. As |R 0 | = k + g + 2 and the subgraphs T (R) are vertex-disjoint, we have |R| ≥ g + 2.
We say that a ring R is embedded plainly in the embedding E if for every central face f of R, the cycle C f that surrounds f in E 0 , is a two-sided cycle in E that bounds a disc on one side, and the graph R − V (C f ) is drawn on the other side. The following lemma is an easy corollary of Lemma 5.1: Lemma 5.4. There exists R ∈ R that is embedded plainly in E.  Proof. Suppose the contrary. For every ring R ∈ R, let C(R) be the cycle around a small face of R that violates the definition of a plainly embedded ring. Consider a graph G = G − M − S − R∈R V (C(R)). We shall prove that it has a large connected component D which contains R := R \ V (C(R)) for each R ∈ R. First, note that R is itself connected and the boundary circles of R of are preserved in R . Thus, it suffices to prove that for every two consecutive rings R 1 , R 2 ∈ R, the inner boundary circle of R 2 is connected to the outer boundary circle of R 1 . Observe that the part of W 4 between these circles is a circular wall of circumference 4 and some positive height. Thus, there are 4 ≥ k + 1 vertex-disjoint paths between the two boundary circles. These paths are disjoint with M and R∈R V (C(R)), and at least one of them must be disjoint with S. Hence, one of these paths is preserved in G . We conclude that the claimed component D indeed exists. It is adjacent to every cycle C(R), so Lemma 5.1, due to our assumption on how cycles C(R) are embedded in E, yields that the Euler genus of the embedding E is at least |R|, which is more than g.
Let R ∈ R be a plainly embedded ring, and let C R be the central circle of R. A direct corollary of the definition of a plainly embedded ring is the following.
Corollary 5.5. In the embedding E, C R is a two-sided cycle, and its incident edges of R are partitioned between the sides of C R exactly as in the embedding E 0 .
Proof. Let e 1 and e 2 be two edges of R \ E(C R ) that are incident to C R that are two consecutive edges on the same side of C R in E 0 . Furthermore, let P be the path between e 1 and e 2 in C R that is not incident to any other edge of R \ E(C R ) on the same side as e 1 , and let f be the face of the embedding of R in E 0 that is incident with e 1 , e 2 , and P ; see also Figure 4. Let e be the other edge of R \ E(C R ) incident to P (the one that is drawn on the opposite side of C R than e 1 in E 0 ). Since R is plainly embedded in E, the embedding E restricted to R has a face surrounded by C f , and thus, as we traverse P in E, the edges e 1 and e 2 are on one side, and e is on the other side. Since the choice of e 1 , e 2 , and f is arbitrary, the claim follows.
Corollary 5.5 allows us to speak about the inner and outer side of C R in E: the sides of C R that contain incident edges inside C R and outside C R in E 0 .
A bridge is a connected component C of G − V (R), together with the edges joining C with V (R). Furthermore, an edge e / ∈ E(R) with both endpoints in V (R) is also a bridge on its own. For a bridge B, the vertices of V (B) ∩ V (R) are attachment points.
A bridge B is central if it has at least one attachment point, but all its attachment point lie in V (C R ). Note that, since R is contained in W 3 , a central bridge is disjoint with M and in the embedding E 0 it is drawn inside one of the small faces of R incident with C R . In particular, a central bridge is a subgraph of the territory of R.
Let H be the subgraph of G − M that consists of: the part of G − M that is enclosed on the same side of C R in the embedding E 0 as the vertex v (i.e., on the disc, flat side of C R ), together with all central bridges. Armed with these observations, we now modify the embedding E of G − S − {v} as follows. First, we cut the surface along the cycle C R , and cap with discs the two resulting holes. This operation can only lead to a surface of a lower Euler genus. Second, we remove all edges of H from E, and all vertices of H that become isolated by this operation. Observe that due to Corollary 5.5, now in E there is a face f , containing one of the discs glued to C R (the one glued on the inner side of C R ).
Note that if we restrict the embedding E 0 to H, we obtain a plane embedding E H of H with an additional property that every vertex of ∂H lies on the outerface.
Consider a bridge B that has an attachment point in V (C R ), but is not central (i.e., is not a subgraph of H). Note that due to the fact that R is plainly embedded, in E the bridge B needs to be drawn in the same face of R as in the embedding E 0 . Thus, the order of the vertices of ∂H on the outerface of E H is exactly the same as the order of these vertices in the modified embedding E . Consequently, the embedding E H of H can be glued into f , identifying correspondingly the vertices of V (H) that remain in E. In this manner, we obtain an embedding E of G − (S \ V (H)), concluding the proof that v is irrelevant.
This finishes the proof of Theorem 1.3.

Conclusions
In this work we have developed fixed-parameter algorithms for the Genus Vertex Deletion problem with solution size and treewidth parameterizations, putting particular effort into optimizing the dependency on the treewidth parameter in the running time bound. We remark that, although our formal statement of Genus Vertex Deletion involves only bounding the Euler genus of the output graph, only minor changes to our algorithms are required if one demands the final graph to be embeddable in an orientable surface of some genus. In terms of combinatorial embeddings, studied in Section 3, an embedding is orientable if the set of flags can be partitioned into two parts (called left and right) such that every orbit of σ, θ, and φ contains two flags from different sets. The crucial observation is that deleting an edge, drawing an edge along a face boundary, and suppressing a size-4 vertex that is not isolated, applied to an orientable embedding results in an embedding that is also orientable. Consequently, if we allow only orientable embeddings in the dynamic programming algorithm of Section 4, we obtain the desired variant of Theorem 1.2 for orientable surfaces. Finally, the arguments of Section 5 operate in the language of modifying an embedding in a fixed surface, and therefore yield also without any changes a variant of Theorem 1.3 for orientable surfaces.
We would like to conclude with two open questions, stemming from our research. First: Can we obtain a 2 O(Cgk log k) n-time algorithm, following the ideas of [5] for the planar case? Our bounded treewidth routine suits such an algorithm, but the irrelevant vertex argument does not.
Second, and more challenging: what can we say about possible dependency on the parameter k for the problem of deleting k vertices to an arbitrary minor-closed graph family? A similar question can be asked for the parameter treewidth. Here, the main challenge is that it is harder to certify being H-minor-free for an arbitrary graph H, while one can certify being of bounded genus by giving a corresponding embedding.