{'fraction_non_alphanumeric': 0.0620736157385372, 'fraction_numerical': 0.010451372362367126, 'mean_word_length': 3.6274203909332843, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
How Bad is the Freedom to Flood-It?

Fixed-Flood-It and Free-Flood-It are combinatorial problems on graphs that generalize a very popular puzzle called Flood-It. Both problems consist of recoloring moves whose goal is to produce a monochromatic ("flooded") graph as quickly as possible. Their difference is that in Free-Flood-It the player has the additional freedom of choosing the vertex to play in each move. In this paper, we investigate how this freedom affects the complexity of the problem. It turns out that the freedom is bad in some sense. We show that some cases trivially solvable for Fixed-Flood-It become intractable for Free-Flood-It. We also show that some tractable cases for Fixed-Flood-It are still tractable for Free-Flood-It but need considerably more involved arguments. We finally present some combinatorial properties connecting or separating the two problems. In particular, we show that the length of an optimal solution for Fixed-Flood-It is always at most twice that of Free-Flood-It, and this is tight.


Introduction
Flood-It is a popular puzzle, originally released as a computer game in 2006 by LabPixies (see [2]). In this game, the player is presented with (what can be thought of as) a vertex-colored grid graph, with a designated special pivot vertex, usually the top-left corner of the grid. In each move, the player has the right to change the color of all vertices contained in the same monochromatic (connected) component as the pivot to a different color of her choosing. Doing this judiciously gradually increases the size of the pivot's monochromatic component, until the whole graph is flooded with one color. The goal is to achieve this flooding with the minimum number of moves. See Figure 1 for an example. Following the description above, Flood-It immediately gives rise to a natural optimization problem: given a vertex-colored graph, determine the shortest sequence of flooding moves that wins the game. This problem has been extensively studied in the last few years (e.g. [14,17,19,18,11,6,22,7,20,13,8]; a more detailed summary of known results is given below), both because of the game's popularity (and addictiveness!), but also because the computational complexity questions associated with this problem have turned out to be surprisingly deep, and the problem has turned out to be surprisingly intractable.
The goal of this paper is to add some insights to our understanding of this interesting, puzzle-inspired, optimization problem, by taking a closer look at the importance of the pivot vertex. As explained above, the classical version of the game only allows the player to change the color of a special vertex and its component and has been studied under the name Fixed-Flood-It [17,19,18] (or Flood-It in some papers [2,22,6,7,13]). However, it is extremely natural to also consider a version where the player is also allowed to play a different vertex of her choosing in each turn. This has also been well-studied under the name Free-Flood-It [2,14,17,19,18,6,22]. See, e.g., Figure 2. Since both versions of this problem have been studied before, the question of the impact of the pivot vertex on the problem's structure has (at least implicitly) been considered. Intuitively, one would expect Free-Flood-It to be a harder problem; after all, the player has to choose a color to play and a vertex to play it on, and is hence presented with a larger set of possible moves. The state of the art seems to confirm this intuition, as only some of the positive algorithmic results known for Fixed-Flood-It are known also for Free-Flood-It, while there do exist some isolated cases where Fixed-Flood-It is tractable and Free-Flood-It is hard, for example co-comparability graphs [9,11] and grids of height 2 [2,18]. Nevertheless, these results do not completely pinpoint the added complexity brought by the task of selecting a vertex to play, as the mentioned algorithms for Fixed-Flood-It are already non-trivial, and hence the jump in complexity is likely to be the result of the combination of the tasks of picking a color and a vertex. More broadly, [6] presented a generic reduction from Fixed-Flood-It to Free-Flood-It that preserves a number of crucial parameters (number of colors, optimal value, etc.) and gives convincing evidence that Free-Flood-It is always at least as hard as Fixed-Flood-It, but not necessarily harder.
Our Results We investigate the complexity of Free-Flood-It, mostly from the point of view of parameterized complexity, 1 as well as the impact on the combinatorics of the game of allowing moves outside the pivot.
Our first result is to show that Free-Flood-It is W [2]-hard parameterized by the number of moves in an optimal solution. We recall that for Fixed-Flood-It this parameterization is trivially fixed-parameter tractable: when a player has only k moves available, then we can safely assume that the graph uses at most (roughly) k colors, hence one can easily consider all possible solutions in FPT time. The interest of our result is, therefore, to demonstrate that the task of deciding which vertex to play next is sufficient to make Free-Flood-It significantly harder than Fixed-Flood-It. Indeed, the W[2]-hardness reduction we give, implies also that Free-Flood-It is not solvable in n o(k) time under the ETH (Exponential Time Hypothesis). This tightly matches the complexity of a trivial algorithm which considers all possible vertices and colors to be played. This is the first concrete example showing a case where Fixed-Flood-It is essentially trivial, but Free-Flood-It is intractable.
Motivated by this negative result we consider several other parameterizations of the problem. We show that Free-Flood-It is fixed-parameter tractable when parameterized by the number of possible moves and the clique-width. This result is tight in the sense that the problem is hard when parameterized by only one of these parameters. It also implies the fixed-parameter tractability of the problem parameterized by the number of colors and the modular-width. In a similar vein, we present a polynomial kernel when Free-Flood-It is parameterized by the input graph's neighborhood diversity and number of colors.
An analogous result was shown for Fixed-Flood-It in [7], but because of the freedom to select vertices, several of the tricks used there do not apply to Free-Flood-It, and our proofs are slightly more involved. Our previously mentioned reduction also implies that Free-Flood-It does not admit a polynomial kernel parameterized by vertex cover, under standard assumptions. This result was also shown for Fixed-Flood-It in [7], but it does not follow immediately for Free-Flood-It, as the reduction of [6] does not preserve the graph's vertex cover.
Motivated by the above results, which indicate that the complexity of the problem can be seriously affected if one allows non-pivot moves, we also study some more purely combinatorial questions with algorithmic applications. The main question we pose here is the following. It is obvious that for all instances the optimal number of moves for Free-Flood-It is upper-bounded by the optimal number of moves for Fixed-Flood-It (since the player has strictly more choices), and it is not hard to construct instances where Fixed-Flood-It needs strictly more moves. Can we bound the optimal number of Fixed-Flood-It moves needed as a function of the optimal number of Free-Flood-It moves? Somewhat surprisingly, this extremely natural question does not seem to have been explicitly considered in the literature before. Here, we completely resolve it by showing that the two optimal values cannot be more than a factor of 2 apart, and constructing a family of simple instances where they are exactly a factor of 2 apart. As an immediate application, this gives a 2-approximation for Free-Flood-It for every case where Fixed-Flood-It is known to be tractable.
We also consider the problem's monotonicity: Fixed-Flood-It has the nice property that even an adversary that selects a single bad move cannot increase the optimal (that is, in the worst case a bad move is a wasted move). We construct minimal examples which show that Free-Flood-It does not have this nice monotonicity property, even for extremely simple graphs, that is, making a bad move may not only waste a move but also make the instance strictly worse. Such a difference was not explicitly stated in the literature, while the monotonicity of Fixed-Flood-It was seem to be known or at least assumed. The only result we are aware of is the monotonicity of Free-Flood-It on paths shown by Meeks and Scott [17].
Known results In 2009, the NP-hardness of Fixed-Flood-It with six colors was sketched by Elad Verbin as a comment to a blog post by Sariel Har-Peled [24]. Independently to the blog comment, Clifford et al. [2] and Fleischer and Woeginger [9] started investigations of the complexity of the problem, and published the conference versions of their papers at FUN 2010. Here we mostly summarize some of the known results on Free-Flood-It. For more complete lists of previous result, see e.g. [11,14,7].
Free-Flood-It is NP-hard if the number of colors is at least 3 [2] even for trees with only one vertex of degree more than 2 [14,6], while it is polynomialtime solvable for general graphs if the number of colors is at most 2 [2,17,14]. Moreover, it is NP-hard even for height-3 grids with four colors [17]. Note that this result implies that Free-Flood-It with a constant number of colors is NP-hard even for graphs of bounded bandwidth. If the number of colors is unbounded, then it is NP-hard for height-2 grids [18], trees of radius 2 [6], proper interval graphs and caterpillars [11]. Also, it is known that there is no constant-factor approximation with a factor independent of the number of colors unless P = NP [2].
There are a few positive results on Free-Flood-It. Meeks and Scott [19] showed that every colored graph has a spanning tree with the same coloring such that the minimum number of moves coincides in the graph and the spanning tree. Using this property, they showed that if a graph has only a polynomial number of vertex subsets that induce connected subgraphs, then Free-Flood-It (and Fixed-Flood-It) on the graph can be solved in polynomial time. This in particular implies the polynomial-time solvability on subdivisions of a fixed graph. It is also known that Free-Flood-It for interval graphs and split graphs is fixed-parameter tractable when parameterized by the number of colors [11].
We refer the interested readers to the recent survey on Food-It by Fellows et al. [8] for further details of known results and possible applications in bioinfomatics.

Preliminaries
For a positive integer k, we use [k] to denote the set {1, . . . , k}. Given a graph G = (V, E), a coloring function col : V → [c max ], where c max is a positive integer, and u ∈ V , we denote by Comp(col, u) the maximal set of vertices S such that for all v ∈ S, col(u) = col(v) and there exists a path from u to v such that for all its internal vertices w we have col(w) = col(u). In other words, Comp(col, u) is the monochromatic connected component that contains u under the coloring function col.
Given G, col, a move is defined as a pair (u, i) where u ∈ V , i ∈ [c max ]. The result of the move (u, c) is a new coloring function col defined as follows: col (v) = c for all v ∈ Comp(col, u); col (v) = col(v) for all other vertices. In words, a move consists of changing the color of u, and of all vertices in the same monochromatic component as u, to c. Given the above definition we can also define the result of a sequence of moves (u 1 , c 1 ), (u 2 , c 2 ), . . . , (u k , c k ) on a colored graph with initial coloring function col 0 in the natural way, that is, for The Free-Flood-It problem is defined as follows: given a graph G = (V, E), an integer k, and an initial coloring function col 0 , decide if there exists a sequence of k moves (u 1 , c 1 ), (u 2 , c 2 ), . . . , (u k , c k ) such that the result col k obtained by applying this sequence of moves on col 0 is a constant function (that is, ∀u, v ∈ V we have col k (u) = col k (v)).
In the Fixed-Flood-It problem we are given the same input as in the Free-Flood-It problem, as well as a designated vertex p ∈ V (the pivot). The question is again if there exists a sequence of moves such that col k is monochromatic, with the added constraint that we must have u i = p for all We denote by OPT Free (G, col) the minimum k such that for the input (G, col) the Free-Flood-It problem admits a solution of k moves. We define OPT Fixed (G, col, p) in the same way for the Fixed-Flood-It problem.

Graph parameters
We omit the subscript G when the underlying graph is clear from the context. Vertex cover number: A set S ⊆ V is a vertex cover of a graph G = (V, E) if each edge in E has at least one end point in S. The minimum size of a vertex cover of a graph is its vertex cover number. By vc(G), we denote the vertex cover number of G.
Neighborhood diversity: . Two vertices are twins if they are true twins or false twins. Note that true twins are adjacent and false twins are not. The neighborhood diversity of G, denoted nd(G), is the minimum number k such that V can be partitioned into k sets of twin vertices. It is known that nd(G) ≤ 2 vc(G) + vc(G) for every graph G [15]. Given a graph, its neighborhood diversity and the corresponding partition into sets of twins can be computed in polynomial time [15]; in fact, using fast modular decomposition algorithms, the neighborhood diversity of a graph can be computed in linear time [16,23].
Modular-width: Let H be a graph with k ≥ 2 vertices v 1 , . . . , v k , and let H 1 , . . . , H k be k graphs. The substitution H(H 1 , . . . , H k ) of the vertices of H by H 1 , . . . , H k is the graph with the vertex set 1≤i≤k V (H i ) and the edge set The modular-width of G, denoted mw(G), is defined recursively as follows: • If G has only one vertex, then mw(G) = 1.
• If G is the disjoint union of graphs G 1 , . . . , G h , then • If G is a connected graph with two or more vertices, then where the minimum is taken over all tuples of graphs (H, H 1 , . . . , H k ) such that G = H(H 1 , . . . , H |V (H)| ).
A recursive substitution structure giving the modular-width can be computed in linear-time [16,23]. It is known that mw(G) ≤ nd(G) for every graph G [12]. Clique-width: A k-expression is a rooted binary tree such that • each leaf has label • i for some i ∈ {1, . . . , k}, • each non-leaf node with two children has label ∪, and • each non-leaf node with only one child has label ρ i,j or Each node in a k-expression represents a vertex-labeled graph as follows: • a • i -node represents a graph with one i-vertex; • a ∪-node represents the disjoint union of the labeled graphs represented by its children; • a ρ i,j -node represents the labeled graph obtained from the one represented by its child by replacing the labels of the i-vertices with j; • an η i,j -node represents the labeled graph obtained from the one represented by its child by adding all possible edges between the i-vertices and the j-vertices.
A k-expression represents the graph represented by its root. The clique-width of a graph G, denoted by cw(G), is the minimum integer k such that there is a k-expression representing a graph isomorphic to G. From their definitions, cw(G) ≤ mw(G) holds for every graph G. Figure 3 shows relationships among the graph parameters introduced above together with the well-known treewidth and pathwidth (see [4] for definitions of these two parameters).
clique-width treewidth pathwidth modular-width neighborhood diversity vertex cover number Figure 3: Graph parameters. Each segment implies that the one above is more general than the one below. For example, bounded modular-width implies bounded clique-width but not vice versa.

W[2]-hardness of Free-Flood-It
The main result of this section is that Free-Flood-It is W[2]-hard when parameterized by the minimum length of any valid solution (the natural param-eter). The proof consists of a reduction from Set Cover, a canonical W[2]complete problem.
Before presenting the construction, we recall two basic observations by Meeks and Vu [20], both of which rest on the fact that any single move can (at most) eliminate a single color from the graph, and this can only happen if a color induces a single component.
The proof of Theorem 3.6 relies on a reduction from a special form of Set Cover, which we call Multi-Colored Set Cover (MCSC for short). MCSC is defined as follows: In Multi-Colored Set Cover (MCSC) we are given as input a set of elements R and k collections S 1 , . . . , S k of subsets of R. We are asked if there exist k sets S 1 , . . . , S k such that for all i ∈ [k], S i ∈ S i , and Observe that MCSC is just a version of Set Cover where the collection of sets is given to us pre-partitioned into k parts and we are asked to select one set from each part to form a set cover of the universe. It is not hard to see that any Set Cover instance (S, R) where we are asked if there exists a set cover of size k can easily be transformed to an equivalent MCSC instance simply by setting S i = S for all i ∈ [k], since the definition of MCSC does not require that the sub-collections S i be disjoint. We conclude that known hardness results for Set Cover immediately transfer to MCSC, and in particular MCSC is W[2]-hard when parameterized by k.

Construction
We are now ready to describe our reduction which, given an MCSC instance with universe R and k collections S i (i ∈ [k]) of subsets of R, produces an equivalent instance of Free-Flood-It, that is, a graph G = (V, E) and a coloring function col on V . We construct this graph as follows: • for every set S ∈ S i , construct a vertex in V . The set of vertices in V corresponding to sets of S i is denoted by I i and col(v) = i for each v ∈ I i . I 1 ∪ ... ∪ I k induces an independent set colored {1, ..., k}.
• for each i ∈ [k], construct 3k new vertices, denoted by L i and connect all of them to all vertices of I i such that L i ∪ I i induces a complete bipartite graph of size 3k  • for each vertex v ∈ L i for 1 ≤ i ≤ k, construct k new leaf vertices connected to v with distinct colors 1, ..., k.
• for each element r ∈ R, construct a vertex r with col(u) = k + 1. For each S ∈ S i such that r ∈ S we connect r to the vertex of I i that represents S.
• add a special vertex u with col(u) = k + 1 which is connected it to all vertices in An illustration of G is shown in Figure 4. In the following we will show that (G, col) as an instance of Free-Flood-It is solvable with at most 2k moves if and only if the given MCSC instance has a set cover of size k which contains one set of each S i .
Recall that for each S i there is a vertex in I i in the constructed graph representing S i . Our first k moves consist of changing the color of each of these k vertices to k + 1 in some arbitrary order.
Observe that in the graph resulting after these k moves the vertices with color k + 1 form a single connected component: all vertices of R have a neighbor with color k+1 because S i is a set cover; all vertices with color k+1 in some I i are in the same component as u; and all vertices of i∈[k] L i are connected to one of the vertices we played. Furthermore, observe that this component dominates the graph: all remaining vertices of I i , as well as all leaves attached to vertices of i∈[k] L i are dominated by the vertices of i∈[k] L i . Hence, we can select an arbitrary vertex with color k + 1, say u, and cycle through the colors 1, . . . , k on this vertex to make the graph monochromatic. Now we establish the converse of Lemma 3.4.
Proof: Suppose that there exists a sequence of at most 2k moves solving (G, col). We can assume without loss of generality that the sequence has length exactly 2k, since performing a move on a monochromatic graph keeps the graph monochromatic. Let (u 1 , c 1 ), . . . , (u 2k , c 2k ) be a solution, let col 0 = col, and let col j denote the coloring of G obtained immediately after the jth move has been performed. The key observation that we will rely on is the following: In other words, we claim that for each group I i there exists a vertex that received color k + 1 at some point during the first k moves. Before proceeding, let us prove this claim. Suppose for contradiction that the claim is false. Then, there exists a group I i such that no vertex in that group has color k + 1 in any of the colorings col 0 , . . . , col k . We now consider the vertices of L i and their attached leaves. Since L i contains 3k > k + 2 vertices, there exist two vertices v 1 , v 2 of L i such that {u 1 , . . . , u k } contains neither v 1 , v 2 , nor any of their attached leaves. In other words, there exist two vertices of L i on which the winning sequence does not change colors by playing them or their private neighborhood directly. However, since v 1 , v 2 only have neighbors in I i (except for their attached leaves), and no vertex of I i received color k + 1, we conclude that col k (v 1 ) = col k (v 2 ) = k + 1, that is, the colors of these two vertices have remained unchanged, and the same is true for their attached leaves. Consider now the graph G with coloring col k : we observe that this coloring uses k + 1 distinct colors, and that each color induces a disconnected graph. This is true for colors 1, . . . , k because of the leaves attached to v 1 , v 2 , and true of color k + 1 because of v 1 , v 2 and the fact that no vertex of I i has color k + 1. We conclude that OPT Free (G, col k ) ≥ k + 1 by Lemma 3.2, which is a contradiction, because the whole sequence has length 2k.
Because of claim (i) we can now conclude that for all i ∈ [k] there exists a j ∈ [k] such that col j−1 (u j ) = i. In other words, for each color i there exists a move among the first k moves of the solution that played a vertex which at that point had color i. To see that this is true consider again for contradiction the case that for some i ∈ [k] this statement does not hold: this implies that vertices with color i in col 0 still have color i in col 1 , . . . , col k , which means that no vertex of I i has received color k + 1 in the first k moves, contradicting (i).
As a result of the above, we therefore claim that for all j ∈ [k], we have col j−1 (u j ) = k + 1. In other words, we claim that none of the first k moves changes the color of a vertex that at that point had color k + 1. This is because, as argued, for each of the other k colors, there is a move among the first k moves that changes a vertex of that color. We therefore conclude that for all vertices v for which col 0 (v) = k + 1 we have col j (v) = k + 1 for all j ∈ [k]. In addition, because in col 0 all colors induce independent sets, each of the first k moves changes the color of a single vertex. Because of claim (i), this means that for each i ∈ [k] one of the first k moves changes the color of a single vertex from I i to k + 1. We select the corresponding set of S i in our MCSC solution.
We now observe that, since all vertices of i∈[k] L i retain color k+1 throughout the first k moves, col k is a coloring function that uses k + 1 distinct colors, and colors 1, . . . , k induce disconnected graphs (because of the leaves attached to the vertices of each L i ). Thanks to Lemma 3.2, this means that col −1 k (k + 1) must induce a connected graph. Hence, all vertices of R have a neighbor with color k + 1 in col k , which must be one of the k vertices played in the first k moves; hence the corresponding element is dominated by our solution and we have a valid set cover selecting one set from each S i .
We are now ready to combine Lemmas 3.4 and 3.5 to obtain the main result of this section.
Theorem 3.6 Free-Flood-It is W[2]-hard parameterized by OPT Free , that is, parameterized by the length of the optimal solution. Furthermore, if there is an algorithm that decides if a Free-Flood-It instance has a solution of length k in time n o(k) , then the ETH is false.
Proof: The described construction, as well as Lemmas 3.4 and 3.5 give a reduction from MCSC, which is W[2]-hard parameterized by k, to an instance of Free-Flood-It with k + 1 colors, where the question is to decide whether OPT Free (G, col) ≤ 2k. Furthermore, it is known that MCSC generalizes Dominating Set, which does not admit an algorithm running in time n o(k) , under the ETH [4]. Since our reduction only modifies k by a constant, we obtain the same result for Free-Flood-It.
We note that because of Lemma 3.1 we can always assume that the number of colors of a given instance is not much higher than the length of the optimal solution. As a result, Free-Flood-It parameterized by OPT Free is equivalent to the parameterization of Free-Flood-It by OPT Free + c max and the result of Theorem 3.6 also applies to this parameterization.

Kernel lower bound for Free-Flood-It
As a byproduct of the reduction above, we can show a kernel lower bound for Free-Flood-It parameterized by the vertex cover number.
Let P and Q be parameterized problems. A polynomial-time computable function f : Σ * × N → Σ * × N is a polynomial parameter transformation from P to Q if there is a polynomial p such that for all (x, k) ∈ Σ * × N , • (x, k) ∈ P if and only if (x , k ) = f (x, k) ∈ Q, and If such a function exits, then P is polynomial parameter reducible to Q.
Proposition 3.7 ([1]) Let P and Q be parameterized problems, and P and Q be unparameterized versions of P and Q, respectively. Suppose P is NPhard, Q is in NP, and P is polynomial parameter reducible to Q. If Q has a polynomial kernel, then P also has a polynomial kernel. Proof: The reduction in this section can be seen as a polynomial parameter transformation from "MCSC parameterized by the solution size k and the size |R| of the universe" to "Free-Flood-It parameterized by the vertex cover number" with a polynomial p(k, |R|) = 3k 2 + |R|. To see this observe that the black vertices in Figure 4 form a vertex cover of size 3k 2 + |R|.
Since MCSC is NP-hard and the decision version of Free-Flood-It is in NP, Proposition 3.7 implies that if Free-Flood-It parameterized by the vertex cover number has a polynomial kernel, then MCSC parameterized by k and |R| also has a polynomial kernel.
It is known that Set Cover (and thus MCSC) parameterized simultaneously by k and |R| does not admit a polynomial kernel unless PH = Σ p 3 [5]. This completes the proof.

Clique-width and the number of moves
In this section, we consider as a combined parameter for Free-Flood-It the length of an optimal solution and the clique-width. We show that this case is indeed fixed-parameter tractable by using the theory of the monadic secondorder logic on graphs. As an application of this result, we also show that combined parameterization by the number of colors and the modular-width is fixed-parameter tractable.
To prove the main claim, we show that Free-Flood-It with a constant length of optimal solutions is an MSO 1 -definable decision problem. The syntax of MSO 1 (one-sorted monadic second-order logic) of graphs includes (i) the logical connectives ∨, ∧, ¬, ⇔, ⇒, (ii) variables for vertices and vertex sets, (iii) the quantifiers ∀ and ∃ applicable to these variables, and (iv) the following binary relations: • u ∈ U for a vertex variable u and a vertex set variable U ; • adj(u, v) for two vertex variables u and v, where the interpretation is that u and v are adjacent; • equality of variables.
If G models an MSO 1 formula ϕ with an assignment X 1 , . . . , X q ⊆ V (G) to the q free variables in ϕ, then we write G, X 1 , . . . , X q |= ϕ. It is known that, given a graph of clique-width at most w, an MSO 1 formula ϕ, and an assignment to the free variables in ϕ, the problem of deciding whether G models ϕ with the given assignment is solvable in time O(f (||ϕ||, w) · n 3 ), where f is a computable function and ||ϕ|| is the length of ϕ [3,21]. Proof: Let V i (1 ≤ i ≤ c max ) be the set of vertices with color i in the input graph. We construct an MSO 1 formula ϕ with c max free variables X 1 , . . . , X cmax such that OPT Free (G, col) ≤ k if and only if G models ϕ with the assignment X i := V i for 1 ≤ i ≤ c max . We can define the desired formula ϕ(X 1 , . . . , X cmax ) as follows: where color c,i (u) for 0 ≤ i ≤ k implies that the color of u is c after the moves We define color c,i (u) recursively as follows. We first set color c,0 (u) := (u ∈ X i ). This is correct as we assign V i to X i . For 1 ≤ i ≤ k, we set where SameCCC i (u 1 , u 2 ) implies that u 1 and u 2 are in the same monochromatic component after the moves (v 1 , c 1 ), . . . (v i , c i ). The formula precisely represents the recursive nature of the colors of the vertices. That is, a vertex u is of color c after the ith move (v i , c i ) if and only if either its color is changed to c by the i move, or it was already of color c before the ith move and its color is not changed by the i move.
Given that color c,i (u) is defined for all c and u, defining SameCCC i (u 1 , u 2 ) is a routine: Since k ≥ c max −1 by Lemma 3.1, it holds that ||ϕ|| is bounded by a function of k.    Proof: Observe that for every connected graph G of modular-width at most w, it holds that OPT Free (G, col) ≤ w + c max − 2: we pick one vertex v from a module M ; we next color one vertex in each module except M with col(v); we then play at v with the remaining c max − 1 colors. Thus we can assume that k ≤ w +c max −2. Since the modular-width of a graph is at most its clique-width by their definitions, Theorem 4.1 gives an O(g(w + c max , w) · n 3 )-time algorithm for some computable g, which can be seen as an O(f (c max , w)·n 3 )-time algorithm for some computable f .

Neighborhood diversity and the number of colors
Since the modular-width of a graph is upper bounded by its neighborhood diversity, Corollary 4.2 in the previous section implies that Free-Flood-It is fixed-parameter tractable when parameterized by both the neighborhood diversity and the number of colors. Here we show that Free-Flood-It admits a polynomial kernel with the same parameterization. This section is devoted to a proof of the following theorem.
Theorem 5.1 Free-Flood-It admits a kernel of at most nd(G) · c max · (nd(G) + c max − 1) vertices.
Fellows et al. [7] observed that for Fixed-Flood-It, a polynomial kernel with the same parameterization can be easily obtained since twin vertices of the same color can be safely contracted. In Free-Flood-It, this is true for true twins but not for false twins. See Figure 5a.
Though it might be still possible to show something like "if there are more than some constant number of false twins with the same color, then one can remove one of them without changing the minimum number of moves," here we show a weaker claim. Our reduction rules are as follows: • Rule TT : Let u and v be true twins of the same color in (G, col). Remove v.
• Rule FT : Let F be a set of false-twin vertices of the same color in (G, col) such that |F | = nd(G) + c max . Remove one arbitrary vertex in F .
Observe that after applying TT and FT exhaustively in polynomial time, the obtained graph can have at most nd(G) · c max · (nd(G) + c max − 1) vertices. This is because each set of twin vertices can contain at most nd(G) + c max − 1 vertices. Hence, to prove Theorem 5.1, it suffices to show the safeness of the rules. Recall that a reduction rule is safe if it produces an equivalent instance.

Lemma 5.2 Rule TT is safe.
Proof: Let u and v be true twins of the same color. Observe that removing v is equivalent to contracting the edge {u, v}. Since u and v are in the same monochromatic component, the lemma holds.
To guarantees the safeness of FT, we need the following technical lemmas. Proof: Let (G , col ) = (G − x, col| G−x ). If a neighbor of x and y has color c, then the lemma trivially holds. Hence, in what follows, we assume that none of the vertices adjacent to x and y has color c. Assume that (u 1 , c 1 ), . . . , (u k , c k ) is valid for at least one of (G, col) and (G , col ). Then there is a move that changes the color of a neighbor of y to c since u i = y for 1 ≤ i ≤ k. Let (u i , c i ) be the first such move. Note that c i = c and that at least one of Comp(col i−1 , u i ) and Comp(col i−1 , u i ) contains a neighbor of y.
The first part (u 1 , c 1 ), . . . , (u i−1 , c i−1 ) of the sequence has the same effect to (G, col) and (G , col ). That is, the monochromatic components and connections among them are the same in (G, col i−1 ) and (G , col i−1 ) except that Let C be the set of monochromatic components of color c in (G, col i−1 ) that are adjacent to Comp(col i−1 , u i ). Similarly, let C be the set of monochromatic components of color c in (G , col i−1 ) that are adjacent to Comp(col i−1 , u i ). Observe that Comp(col i−1 , u i ) = Comp(col i−1 , u i ), C = C \{{x}}, and {y} ∈ C ∩ C . Now we apply the move (u i , c i ). Recall that c i = c. It follows that Comp(col i , u i ) include y, the components Comp(col i , u i ) and Comp(col i , u i ) have the same adjacent monochromatic components. Also, it holds that for each u / ∈ Comp(col i , u i ), Comp(col i−1 , u) = Comp(col i−1 , u). This implies that (G, col i ) and (G , col i ) are equivalent and thus the remaining of the sequence, i.e. (u i+1 , c i+1 ), . . . , (u k , c k ), has the same effect to (G , col i ) and (G, col i ). Therefore, (G, col k ) is constant if and only if so is (G , col k ). (G, col). Let (u 1 , c 1 ), . . . , (u k , c k ) be an optimal valid flooding sequence for (G − x, col| G−x ). Assume that OPT Free (G, col) ≥ k (otherwise we are done). Since |S \ {x}| ≥ OPT Free (G, col) + 1 ≥ k + 1, there is a vertex y ∈ S \ {x} such that u i = y for 1 ≤ i ≤ k. By Lemma 5.3, (u 1 , c 1 ), . . . , (u k , c k ) is valid for (G, col) as well.

Lemma 5.4 Let S be a set of false-twin vertices with the same color in
Next we show the other direction. Since S is a set of monochromatic false-twin vertices, it suffices to show that OPT Free (G, col) ≥ OPT Free (G − x, col| G−x ) for some x ∈ S. Let (u 1 , c 1 ), . . . , (u k , c k ) be an optimal valid flooding sequence of (G, col). Since |S| ≥ OPT Free (G, col) + 2 = k + 2, there are two vertices x, y ∈ S such that u i / ∈ {x, y} for 1 ≤ i ≤ k. By Lemma 5.3, (u 1 , c 1 ), . . . , (u k , c k ) is valid for (G − x, col| G−x ) as well.

Corollary 5.5 Rule FT is safe.
Proof: Let G be a connected graph and col a coloring of G with c max colors. Observe that (G, col) admits a flooding sequence of length nd(G) + c max − 2 as follows. Let T be a maximal set of twin vertices of G and c be a color used in T . For each maximal set of twin vertices T = T of G, pick a vertex u ∈ T and play the move (u, c). After these nd(G) − 1 moves, the vertices of color c form a connected dominating set of G. Now pick a vertex v of color c and play the move (v, c ) for each c ∈ [c max ] \ {c}. These c max − 1 moves make the coloring constant. Now for some color class C and a false-twin class I of (G, col), if |C ∩ I| ≥ c max + nd(G), then we can remove an arbitrary vertex in C ∩ I while preserving the optimal number of steps by Lemma 5.4. This implies the safeness of FT.
Note that using the concept of twin colors, Fellows et al. [7] further reduced the number of colors in instances of Fixed-Flood-It and obtained a (nonpolynomial-size) kernel parameterized by the neighborhood diversity. They say that two colors are twins if the colors appear in the same family of the maximal sets of twin vertices. They observed that, in Fixed-Flood-It, if there are twin colors, then removing all vertices in one of these colors reduces the fewest number of moves exactly by 1. Unfortunately, this is not the case for Free-Flood-It. See Figure 5b.

Relation Between Fixed and Free Flood-It
The main theorem of this section is the following: Theorem 6.1 For any graph G = (V, E), coloring function col on G, and p ∈ V we have OPT Free (G, col) ≤ OPT Fixed (G, col, p) ≤ 2OPT Free (G, col). Theorem 6.1 states that the optimal solutions for Free-Flood-It and Fixed-Flood-It can never be more than a factor of 2 apart. It is worthy of note that we could not hope to obtain a constant smaller than 2 in such a theorem, and hence the theorem is tight. Theorem 6.2 There exist instances of Fixed-Flood-It such that OPT Fixed (G, col, p) = 2OPT Free (G, col).
Proof: Consider a path on 2n + 1 vertices properly colored with colors 1, 2. If we set the pivot to be one of the endpoints then OPT Fixed = 2n. However, it is not hard to obtain a Free-Flood-It solution with n moves by playing every vertex at odd distance from the pivot.
Before we proceed to give the proof of Theorem 6.1, let us give a highlevel description of our proof strategy and some general intuition. The first inequality is of course trivial, so we focus on the second part. We will establish it by induction on the number of non-pivot moves performed by an optimal Free-Flood-It solution. The main inductive argument is based on observing that a valid Free-Flood-It solution will either at some point play a neighbor u of the component of p to give it the same color as p, or if not, it will at some point play p to give it the same color as one of its neighbors. The latter case is intuitively easier to handle, since then we argue that the move that changed p's color can be performed first, and if the first move is a pivot move we can easily fall back on the inductive hypothesis. The former case, which is the more interesting one, can be handled by replacing the single move that gives u the same color as p, with two moves: one that gives p the same color as u, and one that flips p back to its previous color. Intuitively, this basic step is the reason we obtain a factor of 2 in the relationship between the two versions of the game.
The inductive strategy described above faces some complications due to the fact that rearranging moves in this way may unintentionally re-color some vertices, which makes it harder to continue the rest of the solution as before. To avoid this we define a somewhat generalized version of Free-Flood-It, called Subset-Free-Flood-It. Definition 6.3 Given G = (V, E), a coloring function col on G, and a pivot p ∈ V , a set-move is a pair (S, c), with S ⊆ V and S = Comp(col, u) for some u ∈ V , or {p} ⊆ S ⊆ Comp(col, p). The result of (S, c) is the coloring col that sets col (v) = c for v ∈ S; and col (v) = col(v) otherwise.
We define Subset-Free-Flood-It as the problem of determining the minimum number of set-moves required to make a graph monochromatic, and Subset-Fixed-Flood-It as the same problem when we impose the restriction that every move must change the color of p, and denote as OPT S-Free , OPT S-Fixed the corresponding optimum values.
Informally, a set-move is the same as a normal move in Free-Flood-It, except that we are also allowed to select an arbitrary connected monochromatic set S that contains p (even if S is not maximal) and change its color. Intuitively, one would expect moves that set S to be a proper subset of Comp(col, p) to be counter-productive, since such moves split a monochromatic component into two pieces. Indeed, we prove below in Lemma 6.4 that the optimal solutions to Fixed-Flood-It and Subset-Fixed-Flood-It coincide, and hence such moves do not help. The reason we define this version of the game is that it gives us more freedom to define a solution that avoids unintentionally recoloring vertices as we transform a given Free-Flood-It solution to a Fixed-Flood-It solution.
Lemma 6.4 For any graph G = (V, E), coloring function col on G, and pivot p ∈ V we have OPT Fixed (G, col, p) = OPT S-Fixed (G, col, p).
Proof: First, observe that OPT S-Fixed (G, col, p) ≤ OPT Fixed (G, col, p) is trivial, as any solution of Fixed-Flood-It is a solution to Subset-Fixed-Flood-It by playing the same sequence of colors and always selecting all of the connected monochromatic component of p.
Let us also establish the converse inequality. Consider a solution (S 1 , c 1 ), (S 2 , c 2 ), . . . , (S k , c k ) of Subset-Fixed-Flood-It, where by definition we have p ∈ S i for all i ∈ [k]. We would like to prove that (p, c 1 ), (p, c 2 ), . . . , (p, c k ) is a valid solution for Fixed-Flood-It. Let col i be the result of the first i set-moves of the former solution, and col i be the result of the first i moves of the latter solution. We will establish by induction the following: 1. For all i ∈ [k] we have Comp(col i , p) ⊆ Comp(col i , p).

For all
The statements are true for i = 0. Suppose that the two statements are true after i − 1 moves. The first solution now performs the set-move (S i , c i ) with S i ⊆ Comp(col i−1 , p) ⊆ Comp(col i−1 , p). We now have that Comp(col i , p) contains S i plus the neighbors of S i which have color c i in col i−1 . Such vertices either also have color c i in col i−1 , or are contained in Comp(col i−1 , p); in both cases they are included in Comp(col i , p), which establishes the first condition. To see that the second condition continues to hold observe that every vertex for which col i−1 (u) = col i (u) or col i−1 (u) = col i (u) belongs in Comp(col i , p); the colors of other vertices remain unchanged. Since in the end Comp(col k , p) = V the first condition ensures that Comp(col k , p) = V .
We are now ready to state the proof of Theorem 6.1.
Proof: [Theorem 6.1] As mentioned, we focus on proving the second inequality as the first inequality follows trivially from the definition of the problems. Given a graph G = (V, E), an initial coloring function col = col 0 , and a pivot p ∈ V , we suppose we have a solution to Free-Flood-It (u 1 , c 1 ), (u 2 , c 2 ), . . . , (u k , c k ). In the remainder, we denote by col i the coloring that results after the moves (u 1 , c 1 ), . . . , (u i , c i ). We can immediately construct an equivalent solution to Subset-Free-Flood-It from this, producing the same sequence of colorings: (Comp(col 0 , u 1 ), c 1 ), (Comp(col 1 , u 2 ), c 2 ), . . . , (Comp(col k−1 , u k ), c k ). We will transform this solution to a solution of Subset-Fixed-Flood-It of length at most 2k, and then invoke Lemma 6.4 to obtain a solution for Fixed-Flood-It of length at most 2k. More precisely, we will show that for any G, col, p we have OPT S-Fixed (G, col, p) ≤ 2OPT S-Free (G, col, p).
For a solution S = (S 1 , c 1 ), (S 2 , c 2 ), . . . , (S k , c k ) to Subset-Free-Flood-It we define the number of bad moves of S as b(S) = |{(S i , c i ) | p ∈ S i }|. We will somewhat more strongly prove the following statement for all G, col, p: for any valid Subset-Free-Flood-It solution S, we have OPT S-Fixed (G, col, p) ≤ |S| + b(S).
Since |S| + b(S) ≤ 2|S|, the above statement will imply the promised inequality and the theorem.
We prove the statement by induction on |S| + 2b(S). If |S| + 2b(S) ≤ 2 then S is already a Subset-Fixed-Flood-It solution, so the statement is trivial. Suppose then that the statement holds when |S| + 2b(S) ≤ n and we have a solution S with |S| + 2b(S) = n + 1. We consider the following cases: • The first move (S 1 , c 1 ) has p ∈ S 1 . By the inductive hypothesis there is a Subset-Fixed-Flood-It solution of length at most |S| + b(S) − 1 for (G, col 1 , p). We build a solution for Subset-Fixed-Flood-It by appending this solution to the move (S 1 , c 1 ), since this is a valid move for Subset-Fixed-Flood-It.
• There exists a move (S i , c i ) with S i = Comp(col i−1 , u), for some u ∈ N (Comp(col i−1 , p)) \ Comp(col i−1 , p) such that c i = col i−1 (p). That is, there exists a move that plays a vertex u that currently has a different color than p, and as a result of this move the component of u and p merge, because u receives the same color as p and u has a neighbor in the component of p.
To see that S is still a valid solution we observe that Comp(col i−1 , p) ∪ Comp(col i−1 , u) is monochromatic and connected when we play it, and that the result of the first i − 1 moves, plus the two new moves is exactly col i . We also note that |S | + b(S ) = |S| + b(S) because we replaced one bad move with two good moves. However, |S | + 2b(S ) < |S| + 2b(S), hence by the inductive hypothesis there exists a Subset-Fixed-Flood-It solution of the desired length.
• There does not exist a move as specified in the previous case. We then show that this reduces to the first case. If no move as described in the previous case exists and the initial coloring is not already constant, S must have a move (S i , c i ) where {p} ⊆ S i ⊆ Comp(col 0 , p) and c i = col i−1 (u) for u ∈ N (Comp(col 0 , p)) \ Comp(col 0 , p). In other words, this is a good move (it changes the color of p), that adds a new vertex u to the connected monochromatic component of p. Such a move must exist, since if the initial coloring is not constant, the initial component of p must be extended, and we assumed that no move that extends it by recoloring one of its neighbors exists.
Consider the first such good move (S i , c i ) as described above. We build a solution S as follows: the first move is (Comp(col 0 , p), col 0 (u)), where u is, as described above, the neighbor of Comp(col 0 , p) with col i−1 (u) = c i . For j ∈ [i − 1] we add the move (S j , c j ) if u ∈ S j , or the move (Comp(col j−1 , u) ∪ Comp(col 0 , p), c j ) if u ∈ S j . In other words, we keep other moves unchanged if they do not affect u, otherwise we add to them Comp(col 0 , p). We observe that these moves are valid since we maintain the invariant that Comp(col 0 , p) and u have the same color and since none of the first i − 1 moves of S changes the color of p (since we selected the first such move). The result of these i moves is exactly col i . We now append the remaining move (S i+1 , c i+1 ), . . ., and we have a solution that starts with a good move, has the same length and the same (or smaller) number of bad moves as S and is still valid. We have therefore reduced this to the first case.
As we mentioned before, this combinatorial theorem implies 2approximability of Free-Flood-It for the cases where Fixed-Flood-It is polynomial-time solvable. Also, as Fixed-Flood-It admits a (c max − 1) approximation [2], 2 we have a 2(c max − 1) approximation for Free-Flood-It. Corollary 6.5 Free-Flood-It admits a 2(c max − 1) approximation, where c max is the number of used colors.

Non-monotonicity of Free-Flood-It
We now consider the (non-)monotonicity of the problem. A game has the monotonicity property if no legal move makes the situation worse. That is, if Fixed-Flood-It (or Free-Flood-It) has the monotonicity property, then no single move increases the minimum number of steps to make the input graph monotone. We believe that the monotonicity of Fixed-Flood-It was known as folklore and used implicitly in the literature. On the other hand, we are not sure that the non-monotonicity of Free-Flood-It was widely known. The only result we are aware of is by Meeks and Scott [17] who showed that on paths Free-Flood-It has the monotonicity property. In the following, we show that Free-Flood-It loses its monotonicity property as soon as the underlying graph becomes a path with one attached vertex.
To be self-contained, we start with proving the following folklore, which says that Fixed-Flood-It is monotone. Proof: Let (p, c 1 ), . . . , (p, c k ) be an optimal solution for (G, col). We show that this sequence is valid for (G, col ) too. Let col = col 0 and for i ≥ 1, let col i be the coloring obtained from col i−1 by applying the ith move (p, c i ).
We define col i in the analogous way. Observe that since all moves are played on the pivot p, we have Comp(col i , v) ∈ {Comp(col, v), Comp(col i , p)} and Comp(col i , v) ∈ {Comp(col , v), Comp(col i , p)} for every v ∈ V (G) and for every i. It suffices to show that Comp(col i , p) ⊆ Comp(col i , p) for all i. This obviously holds when i = 0. Assume that Comp(col i , p) ⊆ Comp(col i , p) for some i ≥ 0. Let v ∈ V (G) \ {p} such that Comp(col, v) is not contained in but adjacent to Comp(col i , p), and thus contained in Comp(col i+1 , p). Since Comp(col i , p) ⊆ Comp(col i , p), the monochromatic component Comp(col, v) is either contained in or adjacent to Comp(col i , p). Therefore, Comp(col, v) ⊆ Comp(col i+1 , p) holds, and thus Comp(col i+1 , p) ⊆ Comp(col i+1 , p). [17] showed the following monotonicity of Free-Flood-It on paths. One may wonder whether the monotonicity property holds in general for Free-Flood-It. The following example, however, shows that it does not hold even for some graphs very close to paths. See the two instances in Figure 6. The instance (G, col ) is obtained from (G, col) by playing the move (v, 3). We show that OPT Free (G, col) < OPT Free (G, col ).

Meeks and Scott
Observe that OPT Free (G, col) = 3: by Lemma 3.2, OPT Free (G, col) ≥ 3, and the sequence (u, 2), (u, 1), (u, 3) floods the graph. Now suppose that OPT Free (G, col ) ≤ 3. By Lemma 3.2, the first move in each optimal solution of (G, col ) has to make the subgraph induced by some color connected, and then the second move has to remove the connected color. We can see that 2 is the only color that can play this role. If the first move is not played on u, then it is played on one of the two color-2 vertices and then the second move is played on the other color-2 vertex. Such a sequence of two moves cannot make either of color-1 or color-3 vertices connected. Thus by Lemma 3.2, it still needs at least two moves. Hence we can conclude that the first move is (u, 2). Now the second move has to remove the color 2, and thus has to be played on u (or equivalently on any vertex in the monochromatic component including u). No matter which color we choose, we end up with an instance with at least two colors that are not connected. Again by Lemma 3.2, this instance needs more than one step, and thus OPT Free (G, col ) > 3.

Concluding remark
The results in this paper somehow infer that Free-Flood-It is often at least as hard as Fixed-Flood-It. One may wonder this is always the case in some sense. Fellows et al. [8] asked the following question in their recent survey: Is there any graph class for which Free-Flood-It can be solved in polynomial time, but Flood-It is NP-hard?
where by Flood-It they mean Fixed-Flood-It. To tackle this problem, our results (e.g., Theorem 6.1) would be useful.