Abstract 1 Introduction 2 Polynomial algorithm for paths with precolored end-vertices 3 Few colors and small distance 4 Few precolored vertices 5 Coloring without demands References

Precoloring Extension with Demands on Paths

Arun Kumar Das ORCID School of Computer and Information Sciences, University of Hyderabad, India Michal Opler ORCID Faculty of Information Technology, Czech Technical University in Prague, Czech Republic Tomáš Valla ORCID Faculty of Information Technology, Czech Technical University in Prague, Czech Republic
Abstract

Let G be a graph with a set of precolored vertices, and let us be given an integer distance parameter d and a set of integer demands d1,,dc. The Distance Precoloring Extension with Demands (DPED) problem is to compute a vertex c-coloring of G such that the following three conditions hold: (i) the resulting coloring respects the colors of the precolored vertices, (ii) the distance of two vertices of the same color is at least d, and (iii) the number of vertices colored by color i is exactly di. This problem is motivated by a program scheduling in commercial broadcast channels with constraints on content repetition and placement, which leads precisely to the DPED problem for paths.

In this paper, we study DPED on paths and present a polynomial time exact algorithm when precolored vertices are restricted to the two ends of the path and devise an approximation algorithm for DPED with an additive approximation factor polynomially bounded by d and the number of precolored vertices. Then, we prove that the Distance Precoloring Extension problem on paths, a less restrictive version of DPED without the demand constraints, and then DPED itself, is NP-complete. Motivated by this result, we further study the parameterized complexity of DPED on paths. We establish that the DPED problem on paths is W[1]-hard when parameterized by the number of colors and the distance. On the positive side, we devise a fixed parameter tractable (FPT) algorithm for DPED on paths when the number of colors, the distance, and the number of precolored vertices are considered as the parameters. Moreover, we prove that Distance Precoloring Extension is FPT parameterized by the distance. As a byproduct, we also obtain several results for the Distance List Coloring problem on paths.

Keywords and phrases:
precoloring extension, distance coloring, FPT, approximation algorithms
Funding:
Michal Opler: This work was supported by the Czech Science Foundation Grant no. 24-12046S.
Tomáš Valla: This work was supported by the Czech Science Foundation Grant no. 24-12046S.
Copyright and License:
[Uncaptioned image] © Arun Kumar Das, Michal Opler, and Tomáš Valla; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Parameterized complexity and exact algorithms
; Theory of computation Problems, reductions and completeness
Related Version:
Full Version: https://arxiv.org/abs/2509.18936
Funding:
This work was co-funded by the European Union under the project Robotics and advanced industrial production (reg. no. CZ.02.01.01/00/22_008/0004590).
Acknowledgements:
We would like to thank Václav Blažej, Dušan Knop, Josef Malík and Ondřej Suchý, with whom we held preliminary discussions and obtained several observations relevant to this research.
Editors:
Ho-Lin Chen, Wing-Kai Hon, and Meng-Tsung Tsai

1 Introduction

Vertex coloring of graphs is one of the most studied and fundamental problems in structural and algorithmic graph theory. A k-coloring of a given graph partitions its vertices into k subsets (color classes) such that there is no edge between two members in the same partition. Graph coloring problems [19] have a rich research history [10, 22, 33, 7], comprising numerous variants and results, due to their significant applications in scheduling [4], resource allocation [26], compiler design [30], computational biology [20], network analysis [3], and geography [14]. We study a particular variant of the vertex coloring problem with three additional constraints. Some of the vertices are already given precolored on input, and the sought coloring must respect these colors. Additionally, we are given required sizes of all color classes (called demands), and finally, we require any two vertices of the same color to lie at a distance of at least d from each other. A vertex coloring that satisfies the last condition is called a d-distance coloring. Hence, classical vertex colorings are exactly 1-distance colorings. Alternatively, d-distance colorings of a graph G correspond to classical vertex colorings of the dth power of G.

Formally, the problem we consider is stated as follows.

Distance Precoloring Extension with Demands (DPED)
Input: A graph G=(V,E) on n vertices, a set of colors C, a non-negative integer d, a partial pre-coloring γ:AC for some AV, and a demand function η:C[n].
Question: Is there a d-distance coloring γ:VC that γ extends γ (i.e., γ(v)=γ(v) for every vA), and for every cC, the number of vertices newly colored by color c is exactly η(c), i.e., |{vVAγ(v)=c}|=η(c).

We address the problem for paths and disjoint unions of paths. Our research is motivated by a real-world scheduling problem of a television broadcasting company: A commercial block of a daily broadcast consists of n slots (n vertices of a path), where some slots have already been allocated the type of commercial (precolored vertices). The commercials are already paid for (the demands are given), and no two commercials of the same type may be allocated close together. The task is thus to find an assignment of commercials to slots (color the vertices) such that no two commercials of the same type are too close (vertices being too close on the path must be colored by distinct colors), and all of the commercials (demands) are used. This original setting leads to a lot of interesting generalizations.

A notable amount of previous research has been done in the direction of the coloring of graphs and most of the problems are proved to be NP-hard depending on the type of the input. There are numerous complexity results for different variants of the coloring problems, for example, in terms of parameters like treewidth [13], distance to cluster and co-cluster [15], number of colors and maximum degree [9], clique modulator [17], or vertex cover [18]. Biró et al. [5] introduced the precoloring extension problem for interval graphs. They proved that the problem is polynomial time solvable when each color is used at most once for precoloring, and NP-complete when they are used twice or more. They also extended the results for graphs with bounded treewidth. They mentioned the problem as a variant of the List Coloring problem [11]. In this problem, each vertex is assigned with a list of colors, and they must be colored with a color from the assigned list. The graph is called L-list colorable if there exists a valid vertex coloring which chooses every color from the assigned lists L, and it is called k-choosable if this is possible for any assignment of lists of size at least k. List coloring has been studied on trees [6], planar graphs [32], and many other graph classes [29].

Yet another studied variant of coloring, the Equitable Coloring problem [25], requires the difference between the total number of vertices colored with two different colors to be at most one. Hence Coloring with Demands can be seen as a direct generalization of this notion. In practice, it is common to combine multiple constraints for coloring problems in order to address various applications, e.g., Pelsmajer [27] studied the problem of equitable list coloring. In the Distance Coloring problem, monochromatic vertices cannot occur within a given distance from each other. This generalization of coloring has also been studied extensively [28, 2, 1]. As stated earlier, the problem of coloring paths is motivated by scheduling problems and it has been studied for many other variants, including call scheduling [12], nonrepetitive list colourings [16], radio k-colorings [8] etc.

Figure 1: A pictorial representation of the results.

In this paper, we study the complexity of DPED when G is the union of disjoint paths. We prove that the decision version of the problem is NP-complete when the number of colors, the number of precolored vertices, and the minimum distance d between two vertices of the same color are part of the input. This hardness motivates the study of the problem in terms of parameterized complexity. We reduce the problem to the problem of List Coloring with Demands. We show that both problems are W[1]-hard when parameterized by distance and the number of colors. We prove that the hardness holds for the list coloring problem even if we drop the condition of distance coloring. However, the problem admits an FPT algorithm when we drop the demands and consider only the distance, implying that Distance Precoloring Extension on paths is also FPT by distance. Both problems remain NP-complete when the number of colors, the number of precolored vertices, and the distance are considered a part of the input. On the positive side, we prove that DPED is polynomial time solvable on a single path when the precolored vertices appear only at the ends. Further, we show that DPED on path instances is FPT when the number of colors, the distance parameter, and the number of precolored vertices are considered as parameters simultaneously. Then we present an approximation algorithm that runs in time pdO(d)+O(nlogc) and provides an additive approximate solution with an error of O(d2p). Finally, we establish the NP-completeness of the problems of Distance List Coloring and Distance Precoloring extension on paths. The relationships between the problems and the results are illustrated in Figure 1. We pose the complexity of the Precoloring Extension with Demands on paths as an interesting open problem.

The paper is organized as follows. Section 2 presents a polynomial time solution for the DPED problem on a path having only its ends precolored. In Section 3 we establish the W[1]-hardness of DPED when the parameters are the number of colors and the distance. Section 4 contains results for special cases, when the problem parameters (number of precolored vertices, number of colors, distance) are in some sense limited: we present an approximation algorithm with small additive error and an exact FPT algorithm. Finally, Section 5 presents dynamic programming algorithm and NP-completeness results for the variant without the demands.

2 Polynomial algorithm for paths with precolored end-vertices

As our first result, we show that Distance Precoloring Extension with Demands can be solved in polynomial time whenever we allow precolored vertices only at the ends of the path. In this setting, we are coloring a path G with vertices v1,,vn with a precoloring γ that assigns colors to some initial segment v1,,vs and some final segment vt,,vn. We say that such an instance of DPED is end-precolored. We describe a greedy algorithm that solves end-precolored instances of DPED in polynomial time, regardless of both the number of colors and the distance parameter.

The algorithm colors the vertices in their left-to-right order along the path, starting with the first uncolored vertex. For each vertex, it computes a set of feasible colors for the current vertex and chooses the one with the highest remaining demand. In case of a tie, the algorithm chooses the color that appears earlier in the precoloring of the final segment of the path. We remark that to compute the set of feasible colors for vertex v, it is necessary to exclude not only colors of the previous d vertices to the left of v but also the precolored endsegment in case v is at distance at most d from it. The technique is formally described in Algorithm 1.

Algorithm 1 Greedy algorithm for end-precolored DPED.
Theorem 1.

Algorithm 1 solves DPED on end-precolored paths in time O(nlogc) where n is the number of vertices and c is the number of colors.

Proof.

For contradiction, assume that Algorithm 1 fails, that is, there exists a feasible solution to the instance, and the algorithm does not find any. Let us denote the vertices of the path P as v1,v2,,vn from left to the right and let R={vt,,vn} be the right precolored segment of P. Let the algorithm produce a partial coloring γ and let γ be a feasible solution where the index i satisfying γ(vj)=γ(vj) for all j<i and γ(vi)γ(vi) is the maximum possible. We are going to modify γ such that we obtain another feasible solution that agrees with γ even on γ(vi).

Let a=γ(i) and b=γ(i). By alternating ba-sequence starting at vi we denote a maximal subsequence S=(s1,s2,sk) of the vertices vi,vi+1,,vn such that s1=vi, γ(sj)=b for odd j and γ(sj)=a for even j, the distance of sj and sj+1 is at most d for every j[k1], and no vertex sj is precolored. Observe that when the algorithm was assigning color to vi, the remaining demand of the color a was at least the remaining demand of the color b, and that there is no color a in the distance less than d of the vertex vi. Also note that for an alternating ba-sequence s1,,sk, there can be no vertex of P between any si and si+1 colored by a or b, as this would break the distance property. Let us distinguish several cases.

First, consider the case when the last element of the sequence S is closer than d to the right precolored part R of P. In this case the sequence S must contain all occurrences of color a and b among the vertices from vi to vn in γ. This implies that S is an even sequence, as the demand of a was at least the demand of b. If the vertices from R contain neither color a nor color b, we can freely swap the colors a and b in S. Suppose now the vertices from R contain color a (or b). If there is no occurrence of a or b in R that is within distance d of sk, then the colors a and b can be swapped in γ. If the first occurrence of a or b in R is within distance d of sk, it must be b because sk is colored a by γ, but this contradicts the fact that the algorithm has colored si with a instead of b.

Next, assume that the alternating ba-sequence S starting at vi has even length and its last element is more than d vertices away from the precolored right part R of P. We can freely swap the colors a and b at the vertices of S as there is no conflict both to the left and right of S, thus obtaining a feasible solution γ′′ with greater index i.

It remains to solve the case when S has odd length and its last element is more than d vertices far from the precolored right part R of P. The sequence S contains one more color b than a and as the algorithm has chosen the color a for vi (which means the remaining demand of b was not greater than a), there must exists alternating ab-sequence S starting at some vertex w of odd length, S disjoint from S, which thus contains one more color a than b. We may assume that S is not within distance d to the right precolored part R: if this is the case, we either obtain a contradiction if a occurs before b in R and a and b had the same demand, or we can recolor S and S without problems. We may now swap the colors a and b both in S and S, which does not change the total number of colors used. This produces a feasible solution γ′′ with greater index i.

We obtained the contradiction in all cases, which shows the correctness of the algorithms. The time complexity O(nlogc) follows from using a smarter data structure for assigning the available colors: we may dynamically maintain a binary heap containing the set of feasible colors Cf with the key being a combination of the remaining demand with position (pos()) and the value stored being the color label.

3 Few colors and small distance

In this section, we focus on solving general instances of DPED when both the number of colors and the distance parameter are not too large. We stress that this additional assumption is very natural, e.g., for the original scheduling motivation.

First, we observe that we can solve DPED in this regime in polynomial time, provided that the number of colors and the distance parameter d are constant. The algorithm follows a standard dynamic programming approach for coloring and thus, we provide here only a brief sketch with all the details available in the full version.

Proposition 2.

An instance (G,C,d,γ,η) of DPED on paths can be solved in time cO(d)nc+1 where n is the number of vertices and c is the number of colors.

Proof sketch.

Let γi be a d-distance coloring of an initial segment {v1,,vi} of the path G. The signature of γi consists of the colors of the rightmost d vertices together with the frequencies of individual colors as used by γi. The algorithm sequentially computes for each i[n] all possible signatures of d-distance colorings of {v1,,vi} that, moreover, extend the precoloring γ. At the end, this suffices to check whether there is a d-distance coloring of {v1,,vn} that extends γ and the frequencies of colors used equal the demands.

It is only natural to ask whether we can achieve a polynomial runtime in this regime where the degree of the polynomial is independent of both c and d. We answer this question negatively, under standard theoretical assumptions, by showing that DPED is W[1]-hard with respect to both of these parameters.

Theorem 3.

DPED is W[1]-hard on paths with respect to the number of colors and the distance d.

We first show W[1]-hardness of a related coloring problem, namely List Coloring with Demands. We define the problem formally as follows.

List Coloring with Demands (LCD)
Input: A graph G=(V,E) on v vertices, a set of colors C, a function L:V2C that assigns a list of colors L(v) to each vertex, and a demand function η:C[n].
Question: Is there an L-list coloring γ:VC that satisfies the demands η?

An instance (G,C,η,L) of LCD is a path instance if the graph G is a disjoint union of paths. Moreover, a path instance of LCD is non-alternating if there does not exist a color cC and three consecutive vertices vi1,vi,vi+1 on some path such that cL(vi) and simultaneously cL(vi1)L(vi+1).

The LCD problem has already been shown to be W[1]-hard on paths with respect to the number of colors by Gomes, Guedes, and dos Santos [15] albeit under a different name of Number List Coloring. However, the produced instances of LCD therein are very far from having the non-alternating property that is crucial in proving Theorem 3. We devise a novel reduction from a multidimensional version of the subset problem that, moreover, produces non-alternating path instances of LCD. Due to the space constraints, we omit the proof which can be found in the full version.

Theorem 4.

LCD is W[1]-hard with respect to the number of colors even when restricted to non-alternating path instances.

Theorem 3 is obtained through a polynomial-time reduction from LCD on non-alternating path instances. Crucially, both the distance parameter and the number of colors in the produced DPED instance are linear in the number of colors in the original LCD instance.

Proof of Theorem 3.

For technical reasons, we first modify the LCD instance to guarantee that it is a single path, and both of its endpoints have a list identical to its only neighbor v. That is achieved by introducing two extra colors a,b and concatenating all paths in arbitrary order with two extra vertices in between consecutive pairs and two extra vertices at the very beginning and end where we add {a,b} to the list of all vertices and set L(v)={a,b} for each new vertex. Finally, we set η(a)=η(b)=p+1 where p is the total number of paths in G. It is easy to see that the modified instance is equivalent. Furthermore, the modified instance remains non-alternating because there are two extra new vertices between any pair of original paths, and the colors a,b are included in the list of every vertex.

From now on, we assume that G is a single path with vertices v1,,vn and edges e1,,en1 such that ei={vi,vi+1} for each i[n1]. Moreover, we have L(v1)=L(v2) and L(vn1)=L(vn).

Now, we show that the lists of such a non-alternating LCD path instance can be alternatively represented by lists of forbidden colors for each edge. It is crucial that the instance of LCD is non-alternating, as otherwise, this may not be possible. Moreover, we will also guarantee that any fixed color can be contained in the forbidden sets of at most two consecutive edges.

Claim 5.

We can compute in polynomial time an assignment of color sets to edges F:E(G)2C such that for every vertex v, we have L(v)=C(F(e)F(e)) where e,e are the two edges incident to v, or L(v)=CF(e) if v is incident to a single edge e. Moreover, there are no three consecutive edges ei1, ei and ei+1 such that the intersection F(ei1)F(ei)F(ei+1) is non-empty.

Proof.

We define the assignment inductively along the path. We set F(e1)=CL(v1) and F(en1)=CL(vn). Recall that we first modified the instance to guarantee that each endpoint of the path has an identical list to its neighbor, i.e., L(v1)=L(v2) and L(vn1)=L(vn). For i{2,,n2}, we let F(ei) contain a color cC if and only if cL(vi)L(vi+1) and moreover, either (i) cF(ei1), or (ii) cL(vi+2). See Figure 2. Clearly, F can be computed in polynomial time.

Figure 2: Representation of LCD with forbidden colors when C={c1,c2,,c6,a,b}.

Let us verify the properties of F. For the endpoints v1 and vn, we have L(v1)=CF(e1) and L(vn)=CF(en1) by definition. Now, fix arbitrary i{2,,n1} and a color cC. If we have cL(vi), then neither F(ei1) nor F(ei) contain c by definition and cC(F(ei1)F(ei)). On the other hand, if cL(vi), it follows from the non-alternating property that either cL(vi1) or cL(vi+1). We consider the three possible cases. First, assume that c appears in none of the lists L(vi1), L(vi), and L(vi+1). Then either cF(ei1) or we have cF(ei1) which triggers the condition (i) in the definition of F(ei) and either way, we get that cF(ei1)F(ei). Second, assume that c appears in the list L(vi+1) but not in L(vi1). In this case, we have cF(ei1) by condition (ii) in the definition of F(ei1) and again, we see that cF(ei1)F(ei). Finally, assume that c appears in the list L(vi1) but not in L(vi+1). In this case, we have cF(ei1), which implies cF(ei) by condition (i) in the definition. In all cases, we obtained cF(ei1)F(ei).

Assume for a contradiction that there are three consecutive edges ei1, ei and ei+1 such that the intersection F(ei1)F(ei)F(ei+1) is non-empty and let c be an arbitrary color in the intersection. However, observe that in the definition of F(ei) neither condition (i) nor (ii) holds for c and thus, we must have cF(ei).

With this assignment F, we are finally ready to define the path instance (G,C,d,γ,η) of DPED. Let t denote the size of the color set C and let C={c1,,ct} be an arbitrary enumeration of the colors. We set d=2t+1. We take the graph G to be a path of length nd+1 on vertices v1,,vnd+1 in this order along the path. To simplify the exposition, we partition the vertices into two distinct sets. Every vertex v(k1)d+1 for some k[n] is a main vertex and we denote it alternatively by xk. All the remaining vertices are auxiliary. For i[n1], j[t] and α[2], the vertex v(i1)d+2j+α1 is an auxiliary vertex associated to color cj and we alternatively denote it by yj,αi. Observe that every two consecutive main vertices xi and xi+1 are separated by exactly 2t auxiliary vertices that are grouped into pairs associated to colors c1,,ct in this order. More specifically, the segment between xi and xi+1 contains the auxiliary vertices yj,αi for all j[t] and α[2], ordered lexicographically by the pairs (j,α). See Figure 3.

Figure 3: Construction of G from G. Extending from Figure 2, γ(yj,α2)=γ(yj,α2), except for y4,22 and y5,22.

Our goal is to define a pre-coloring of all the auxiliary vertices such that there is a one-to-one correspondence between feasible colorings of the main vertices and feasible colorings of the original LCD instance. As a final ingredient, we need to be able to assign extra colors to certain vertices without affecting the rest of the instance. To that end, we set C=CC where C={c0,,cd} is a set of auxiliary colors disjoint from C. Moreover, we define an auxiliary coloring γ:V(G)C where γ(vi)=cimod(d+1) for each i[nd+1]. Informally, the coloring γ simply cyclically iterates through the sequence of auxiliary colors c0,,cd along the path, starting with c1. Clearly, γ is a proper d-distance coloring of G.

We define the pre-coloring γ of every auxiliary vertex. For i[n1] and j[t], we set

γ(yj,1i) ={cjif cjF(ei) and cjF(ei1).γ(yj,1i)otherwise.
γ(yj,2i) ={cjif cjF(ei)F(ei1).γ(yj,2i)otherwise.

where we additionally define F(e0)= for simplicity.

First, observe that the pre-coloring γ exactly encodes the assignment of forbidden colors to edges.

Observation 6.

A color cjC appears in the pre-coloring γ on the segment between main vertices xi and xi+1 if and only if cjF(ei).

Moreover, we show that γ distributes the occurrences of a fixed color at a sufficient distance from each other.

Claim 7.

The pre-coloring γ does not contain any monochromatic pair of vertices at a distance at most d.

Proof.

Assume for a contradiction that γ does contain such a pair of monochromatic vertices. We have already observed that γ is a proper d-coloring on a disjoint set of auxiliary colors and thus, this pair must use some color cjC. We cannot have γ(yj,1i)=γ(yj,2i)=cj for any fixed i,j since the respective conditions in the definition of γ are mutually exclusive.

For any different i,i[n1] with i<i and arbitrary α,α[2], the distance between yj,αi and yj,αi is at most d if and only if ii=1 and αα. We cannot have γ(yj,1i)=γ(yj,1i+1)=cj by definition of γ(yj,1i+1). So the only option left is that γ(yj,2i)=γ(yj,αi+1)=cj for either α[2]. But in that case, we have cjF(ei1)F(ei) since γ(yj,2i)=cj and simultaneously, cjF(ei+1) since γ(yj,αi+1)=cj. Thus, we reached a contradiction since F does not contain the same color in the sets F(ei1),F(ei),F(ei+1) of three consecutive edges.

To finish the construction, it remains to define the demand function η. We set η(cj)=η(cj) for every original color cjC and we set η(cj)=0 for every auxiliary color cjC.

Correctness (“only if”).

Suppose that (G,C,η,L) is a yes-instance of LCD and let ρ:V(G)C be an L-list coloring that meets the demands. We define a coloring γ:V(G)C by simply setting γ(xi)=ρ(vi) for every main vertex xi and γ(yj,αi)=γ(yj,αi) for every auxiliary vertex yj,αi. The coloring γ is an extension of γ by definition, and it meets the demands because the demand functions η and η are equal when restricted to the color set C. Thus, it remains to show that γ is a proper d-distance coloring.

Assume for a contradiction that γ contains a pair of monochromatic vertices u and w at a distance at most d. At least one of these vertices has to be a main vertex since the colors of all auxiliary vertices are fixed by γ and there is no such monochromatic pair of pre-colored vertices by Claim 7. First, assume that both u and w are main vertices. Two main vertices are in distance at most d if and only if they are consecutive, i.e., we have without loss of generality u=xi and w=xi+1 for some i[n1]. But then they cannot share the same color since γ(xi)=ρ(vi), γ(xi+1)=ρ(vi+1) and ρ is a proper list-coloring of G. Otherwise, suppose without loss of generality that u is a main vertex xi and w is an auxiliary vertex. The coloring γ can use only the colors from C on the main vertices and thus, we have γ(xi)=γ(w)=cj for some cjC. Moreover, the vertex w lies either on the segment between xi1 and xi or on the segment between xi and xi+1 as those are the only auxiliary vertices at a distance at most d from xi. Observation 6 then implies that we have either cjF(ei1) or cjF(ei). But we know that L(xi)=C(F(ei1)F(ei)) by Claim 5. In particular, the color cj does not appear in the list L(vi), which is a contradiction with ρ being a proper list-coloring since ρ(vi)=γ(xi)=cj.

Correctness (“if”).

Now suppose that (G,C,d,γ,η) is a yes-instance of DPED and let γ:V(G)C be a witnessing d-distance coloring, i.e., γ extends the pre-coloring γ and meets the demands given by η. We define a coloring ρ:V(G)C by simply restricting γ to the main vertices, that is we set ρ(vi)=γ(xi). First, observe that the range of ρ is indeed only the color set C since the demand η(cj) of any auxiliary color is zero and thus, γ uses only the colors from C on the main vertices. Moreover, we have ρ(vi)ρ(vi+1) for every i[n1] because the main vertices xi and xi+1 are at distance d in G. The demands are also satisfied by ρ because the demand functions η and η are equal when restricted to the color set C.

It remains to check that ρ is an L-list coloring, i.e., we have ρ(vi)L(vi) for all i[n]. Assume for a contradiction that this does not hold for a vertex vi with ρ(vi)=γ(xi)=cj. By Claim 5, the color cj belongs to at least one of the sets F(ei1) and F(ei). Observation 6 implies that the color cj is used by γ on some auxiliary vertex from the segment between xi1 and xi+1. But all these vertices are at a distance at most d from xi and we reach a contradiction with γ being a proper d-distance coloring.

4 Few precolored vertices

In this section, we consider the regime when we are given only a few precolored vertices. We present two effective algorithms for DPED in this regime. We first show that an approximation FPT algorithm with small additive error is possible even in the case of many colors. Afterwards, we present an exact FPT algorithm when the number of colors is small as well.

4.1 Approximation

Next, we show there is an approximation algorithm for DPED with additive error, which is bounded by a polynomial function of the distance parameter and the number of colors. By having additive error α we mean that for the set of colors C and demands η:C[n] the algorithm produces coloring γ:VC such that

cC|η(c)|γ1(c)A||α.
Theorem 8.

Let us have an instance of DPED on path P of length n with p precolored vertices, and let c=|C|d+2. There is an approximation algorithm that runs in time pdO(d)+O(nlogc) and outputs a coloring with an additive error at most O(pd2).

Proof.

The approximation algorithm is as follows. We ignore all precolored vertices and we run the greedy Algorithm 1 to color the path P. Let the precolored vertices be denoted w1,,wp, respectively, along the path P, which consists of vertices v1,,vn from left to right. Let b=2(d+1)2. Then we remove the colors in the neighborhood of diameter b around each precolored vertex wi (that is, for the vertices vj whose distance to some wi is at most b). The idea is now to reassign the colors to these discolored vertices while introducing only a small additive error.

First we handle all pairs of vertices (wi,wi+1) such that dist(wi,wi+1)2b as follows. If |C|2d+1, it is easy to find the coloring of the gap between wi and wi+1 in a greedy manner. If |C|<2d+1, we produce d-distance coloring of each segment of consecutive gaps of size at most 2b by dynamic programming in time pdO(d). We may thus further assume that all remaining uncolored gaps between pairs of vertices (wi,wi+1) have dist(wi,wi+1)>2b. For a precolored vertex wi, which equals to some vj, let us denote by left neighborhood of wi those vertices vk, where dist(vk,vj)b and k<j. Similarly, we define the right neighborhood as vertices vk where dist(vk,vj)b and k>j. We now describe the procedure that colors the diameter b neighborhood of each wi, first the left neighborhood and then the right neighborhood (provided that the respective neighborhood is still uncolored). Observe that if the right neighborhood of wi and left neighborhood of wi+1 are both uncolored then they are disjoint as dist(wi,wi+1)>2b. We split the b vertices of the left neighborhood into 2(d+1) blocks B1,,B2(d+1) of size d+1. Let us denote the d+1 vertices immediately preceding block B1 as B0 and let the d+1 vertices after B2(d+1) be denoted as B2d+3. Here, the vertex wi is the first vertex of B2d+3 and we choose the coloring of B2d+3 to consist of the precoloring of wi followed by arbitrarily chosen valid coloring of the rest of B2d+3. Denote by Bij the color of the vertex uj of the block Bi=u1,,ud+1.

We proceed by partial modification of the coloring of each block Bi into the block Bi+1, for i=0,,2d+1. Let the coloring of B0 be, without loss of generality, 0,1,,d. For the block B1, we copy the coloring from B0, where we remove the occurrence of color B2d+31, shift the colors to the right, and introduce a new first color to be d+1 (that is, an extra color). For the block B2, we copy the coloring from B1, where we replace the first color d+1 into B2d+31. Note that by these two steps, we did not create any color conflict for vertices closer than d. For i=2,,d+1 we now continue in a similar manner: let the coloring of the block B2i1 be copied from the block B2i2, where we remove the occurrence of the color B2d+3i, shift the colors to the right and set B2i1i to d. The coloring of B2i is copied from B2i1, but we set B2ii to B2d+3i. Note that the number of blocks is enough to correctly replace all colors such that at the end the coloring of the block B2d+3 is reached and no coloring conflict is created.

After the coloring of the left neighborhood of wi, we proceed similarly with the right neighborhood (with the difference that the block Bd+2 may now inherit the coloring from the first (greedy) phase. The total running time is clearly pdO(d)+O(nlogc). The additive error introduced by this coloring routine is at most the size of all neighborhoods of the precolored vertices w1,,wp, which is O(pd2).

4.2 Exact algorithm for few colors

We have already seen that DPED is W[1]-hard when parameterized by both the number of colors and the distance, which rules out the existence of an FPT algorithm parameterized by these parameters alone under standard assumptions. We have also seen that an FPT approximation algorithm with additive error is possible if there are few precolored vertices and the distance parameter is small, even for an unbounded number of colors. Here, we build on these results and show that an exact FPT algorithm is possible when the number of colors, the distance parameter, and the number of precolored vertices are all small. In some ways, it can also be seen as an extension of the greedy algorithm from Theorem 1 in the case of few colors and small distance. Our approach exploits an intriguing connection between d-distance colorings of paths and regular languages.

A non-deterministic finite automaton (NFA) A is a tuple (Σ,Q,δ,q0,F), where Σ is a finite alphabet, Q is a finite set of states, q0Q is an initial state, FQ is the set of final states, and δQ×Σ×Q is a transition relation. A word w=w1wn over the alphabet Σ is accepted by A if there exists a sequence of states p0,,pn such that p0 is the initial state q0, pn is some final state in F and we have (pi1,wi,pi)δ for every i[n]. We denote by L(A) the language of all words accepted by A.

For a word wΣ and a letter αΣ, we let |w|α denote the number of occurrences of α in w. We assume that Σ={α1,,αk} and we define the Parikh image 𝒫(w) of a word wΣ to be the tuple (|w|α1,,|w|αk)k. In other words, the Parikh image of a word w captures exactly the number of occurrences of each letter from Σ in w. Moreover, for a set of words LΣ, we let 𝒫(L) denote the set of all Parikh images of words in L.

It is known that given a small NFA A over a small alphabet Σ together with a tuple 𝐛, it is possible to efficiently decide whether there exists a word in wL(A) such that 𝒫(w)=𝐛.

Theorem 9 ([21, 31]).

Given an NFA 𝒜 with n states over the alphabet Σ of size k, and a tuple 𝐛k, checking whether 𝐛𝒫(L(𝒜)) can be done in time 2O(k2log(kn)+loglogb) where b=𝐛.

The main theorem of this section follows by reducing DPED to membership for Parikh images of a regular language given by a small NFA. In order to make the argument easier to follow, we use an intermediate problem that asks whether there exists a word in the regular language with a given Parikh image that, moreover, has predetermined letters in some positions. Let P be a relation P×Σ where Σ is a finite alphabet. We say that a word w is P-constrained if we have wi=α for every (i,α)P.

Constrained Membership for Parikh Languages of NFAs (CMPL)
Input: An NFA A over alphabet Σ of size k, a tuple 𝐛k and a relation P×Σ.
Question: Is there a P-constrained word wL(A) such that 𝒫(w)=𝐛?

Theorem 10.

CMPL can be solved in time 2O((k+p)2log((k+p)n)+loglogb) where n is the number states of the NFA A, b=𝐛 and p=|P|.

Due to the space constraints, we omit the proof of Theorem 10.

Theorem 11.

DPED can be solved on path instances in time O(n)+2O(d(c+q)2log(c+q))(logn)O(1) where c is the number of colors, d is the distance parameter and q is the number of precolored vertices.

Proof.

Let (G,C,d,γ,η) be an instance of DPED. As we have observed before, we can assume that G is in fact a single path on vertices v1,,vn in this order along the path.

We start by showing that proper d-distance colorings of paths form a regular language over C. But first, we need some notation. For an alphabet Σ and a positive integer t, we let Σt denote the set of all words of length at most t over Σ with no repeated letters, including the empty word ε. Moreover for word wΣt and letter αw, we let ψt(w,α) be an operation which appends the letter α at the end of w and then possibly deletes the first letter if w already has length t.

Figure 4: The NFA A[4],2 that accepts exactly the 2-distance colorings of paths using colors {1,,4}. The initial state ϵ is in the center, all its states are final and for improved readability, we omit all transitions from states with two colors except for 12, 13 and 14.

Now we can define the NFA AΣ,t=(Σ,Σt,δ,ε,Σt) where (w,α,w)δ if and only if ψt(w,α)=w. The language L(AΣ,t) clearly contains exactly those words over Σ that do not contain two occurrences of the same letter at a distance less than t+1 from each other. See Figure 4. Therefore, the NFA AC,d accepts exactly valid d-distance colorings of paths, and we can solve DPED with no precolored vertices by invoking Theorem 9 for the NFA AC,d where the tuple 𝐛 encodes the demand function η.

Moreover, we can encode the precolored vertices as additional constraints. In particular, we define a set of constraints P where (i,α)P if and only if the vertex vi is precolored and γ(vi)=α. Additionally, we set 𝐛c where bj=η(j)+|γ1(j)| for each j[c]. Observe that the mapping wγw where γw(vi)=wi is a bijection between P-constrained words with 𝒫(w)=𝐛 and proper distance d-colorings of G that extend γ and satisfy the demands η. In other words, (G,C,d,γ,η) is yes-instance of DPED if and only if (AC,d,𝐛,P) is a yes-instance of CMPL.

To finish the proof, it remains to invoke the algorithm of Theorem 10 on the produced NFA A, the tuple 𝐛, and the set of constraints P. The desired runtime follows since the automaton AC,d has O(cd) states and the alphabet is exactly the set of colors C of size c.

5 Coloring without demands

In this section, we focus on variants of the two problems (Precoloring Extension and List Coloring) on paths where we no longer specify demands for each color, but we still require vertices at distance at most d to receive different colors. We refer to these problems as Distance Precoloring Extension (DPE) and Distance List Coloring (DLC). Due to the space constraints, we defer most proofs from this section to the full version.

We show that DPE is NP-complete on paths by reduction from Precoloring Extension on unit interval graphs [24]. We remark that unit interval graphs are a suitable source of hardness since it is known that unit interval graph are precisely the induced subgraphs of path powers [23]. As a consequence, we obtain the NP-completeness of DPED on paths.

Theorem 12.

DPE is NP-complete even when restricted to paths.

Corollary 13.

DPED is NP-complete even when restricted to paths.

Proof of Corollary 13.

Let (G,C,d,γ) be an instance of DPE where G is a path with n vertices. We construct an instance (G,C,d,γ,η) where G is simply obtained by adding (|C|1)n isolated vertices (paths of zero length) to G and setting η(a)=n for every aC. Clearly, every d-distance coloring of G that extends γ induced the desired d-distance coloring of G, regardless of the demands. On the other hand, we can extend any d-distance coloring γ of G to G by coloring exactly n|γ1(a)| of the isolated vertices with each color aC to satisfy all demands.

Finally, we construct an equivalent instance of DPED on a single path. It suffices to concatenate all the disjoint paths in G to a single path while adding d auxiliary vertices between each consecutive pair of original paths. These auxiliary vertices are then greedily precolored with 2d+1 new auxiliary colors disjoint from C that have zero demands. In this way, the d-distance colorings of individual paths from G are independent from each other, and the equivalence follows.

In contrast, we show that the problem Distance Precoloring Extension without demands becomes FPT by the distance parameter d even for an unbounded number of colors. Recall that Distance Precoloring Extension with Demands is W[1]-hard with respect to d by Theorem 3. In fact, we show the existence of an FPT algorithm for the more general problem of Distance List Coloring where the task is to find a list coloring that assigns different colors to every pair of vertices at distance at most d.

Theorem 14.

Distance List Coloring can be solved on paths in time dO(d)n where n is the number of vertices.

References

  • [1] Geir Agnarsson, Raymond Greenlaw, and Magnús M Halldórsson. On powers of chordal graphs and their colorings. Congressus Numerantium, pages 41–66, 2000.
  • [2] Geir Agnarsson and Magnús M. Halldórsson. Coloring powers of planar graphs. SIAM J. Discret. Math., 16(4):651–662, 2003. doi:10.1137/S0895480100367950.
  • [3] Leonid Barenboim, Michael Elkin, and Fabian Kuhn. Distributed (Δ + 1)-coloring in linear (in Δ) time. SIAM J. Comput., 43(1):72–95, 2014. doi:10.1137/12088848X.
  • [4] Sayan Bhattacharya, Deeparnab Chakrabarty, Monika Henzinger, and Danupon Nanongkai. Dynamic algorithms for graph coloring. In Artur Czumaj, editor, Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2018, New Orleans, LA, USA, January 7-10, 2018, pages 1–20. SIAM, 2018. doi:10.1137/1.9781611975031.1.
  • [5] Miklós Biró, Mihály Hujter, and Zsolt Tuza. Precoloring extension. I. Interval graphs. Discret. Math., 100(1-3):267–279, 1992. doi:10.1016/0012-365X(92)90646-W.
  • [6] Hans L. Bodlaender, Carla Groenland, and Hugo Jacob. List colouring trees in logarithmic space. In Shiri Chechik, Gonzalo Navarro, Eva Rotenberg, and Grzegorz Herman, editors, 30th Annual European Symposium on Algorithms, ESA 2022, September 5-9, 2022, Berlin/Potsdam, Germany, volume 244 of LIPIcs, pages 24:1–24:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPICS.ESA.2022.24.
  • [7] Hajo Broersma, Petr A. Golovach, Daniël Paulusma, and Jian Song. On coloring graphs without induced forests. In Otfried Cheong, Kyung-Yong Chwa, and Kunsoo Park, editors, Algorithms and Computation – 21st International Symposium, ISAAC 2010, Jeju Island, Korea, December 15-17, 2010, Proceedings, Part II, volume 6507 of Lecture Notes in Computer Science, pages 156–167. Springer, 2010. doi:10.1007/978-3-642-17514-5_14.
  • [8] Gary Chartrand, Ladislav Nebesky, and Ping Zhang. Radio k-colorings of paths. Discuss. Math. Graph Theory, 24(1):5–21, 2004. doi:10.7151/DMGT.1209.
  • [9] Guilherme de C. M. Gomes, Carlos V. G. C. Lima, and Vinícius Fernandes dos Santos. Parameterized complexity of equitable coloring. Discret. Math. Theor. Comput. Sci., 21(1), 2019. doi:10.23638/DMTCS-21-1-8.
  • [10] Marc Demange, Tínaz Ekim, Bernard Ries, and Cerasela Tanasescu. On some applications of the selective graph coloring problem. Eur. J. Oper. Res., 240(2):307–314, 2015. doi:10.1016/J.EJOR.2014.05.011.
  • [11] Paul Erdős, Arthur L Rubin, and Herbert Taylor. Choosability in graphs. Congr. Numer, 26(4):125–157, 1979.
  • [12] Thomas Erlebach and Klaus Jansen. The complexity of path coloring and call scheduling. Theor. Comput. Sci., 255(1-2):33–50, 2001. doi:10.1016/S0304-3975(99)00152-8.
  • [13] Michael R. Fellows, Fedor V. Fomin, Daniel Lokshtanov, Frances A. Rosamond, Saket Saurabh, Stefan Szeider, and Carsten Thomassen. On the complexity of some colorful problems parameterized by treewidth. Inf. Comput., 209(2):143–153, 2011. doi:10.1016/J.IC.2010.11.026.
  • [14] Robert Freimer. Generalized map coloring for use in geographical information systems. In Ki-Joune Li, Kia Makki, Niki Pissinou, and Siva Ravada, editors, ACM-GIS 2000, Proceedings of the Eighth ACM Symposium on Advances in Geographic Information Systems, November 10-11, 2000, Washington D.C., USA, pages 167–173. ACM, 2000. doi:10.1145/355274.355299.
  • [15] Guilherme C. M. Gomes, Matheus R. Guedes, and Vinícius Fernandes dos Santos. Structural parameterizations for equitable coloring: Complexity, FPT algorithms, and kernelization. Algorithmica, 85(7):1912–1947, 2023. doi:10.1007/S00453-022-01085-W.
  • [16] Jaroslaw Grytczuk, Jakub Przybylo, and Xuding Zhu. Nonrepetitive list colourings of paths. Random Struct. Algorithms, 38(1-2):162–173, 2011. doi:10.1002/RSA.20347.
  • [17] Gregory Z. Gutin, Diptapriyo Majumdar, Sebastian Ordyniak, and Magnus Wahlström. Parameterized pre-coloring extension and list coloring problems. SIAM J. Discret. Math., 35(1):575–596, 2021. doi:10.1137/20M1323369.
  • [18] Lars Jaffke and Bart M. P. Jansen. Fine-grained parameterized complexity analysis of graph coloring problems. Discret. Appl. Math., 327:33–46, 2023. doi:10.1016/j.dam.2022.11.011.
  • [19] Tommy R. Jensen and Bjarne Toft. Graph Coloring Problems. Wiley Series in Discrete Mathematics and Optimization. Wiley, 2011.
  • [20] Susan Khor. Application of graph colouring to biological networks. IET Systems Biology, 4:185–192, 2010. doi:10.1049/iet-syb.2009.0038.
  • [21] Eryk Kopczynski and Anthony Widjaja To. Parikh images of grammars: Complexity and applications. In Proceedings of the 25th Annual IEEE Symposium on Logic in Computer Science, LICS 2010, 11-14 July 2010, Edinburgh, United Kingdom, pages 80–89. IEEE Computer Society, 2010. doi:10.1109/LICS.2010.21.
  • [22] Jan Kratochvíl, Zsolt Tuza, and Margit Voigt. New trends in the theory of graph colorings: Choosability and list coloring. In Ronald L. Graham, Jan Kratochvíl, Jaroslav Nešetřil, and Fred S. Roberts, editors, Contemporary Trends in Discrete Mathematics: From DIMACS and DIMATIA to the Future, Proceedings of a DIMACS Workshop, Stirín Castle, Czech Republic, May 19-25, 1997, volume 49 of DIMACS Series in Discrete Mathematics and Theoretical Computer Science, pages 183–197. DIMACS/AMS, 1997. doi:10.1090/dimacs/049/13.
  • [23] Min Chih Lin, Dieter Rautenbach, Francisco J. Soulignac, and Jayme Luiz Szwarcfiter. Powers of cycles, powers of paths, and distance graphs. Discret. Appl. Math., 159(7):621–627, 2011. doi:10.1016/J.DAM.2010.03.012.
  • [24] Dániel Marx. Precoloring extension on unit interval graphs. Discret. Appl. Math., 154(6):995–1002, 2006. doi:10.1016/j.dam.2005.10.008.
  • [25] Walter Meyer. Equitable coloring. The American mathematical monthly, 80(8):920–922, 1973.
  • [26] Hiroki Osawa, Akira Suzuki, Takehiro Ito, and Xiao Zhou. Algorithms for coloring reconfiguration under recolorability constraints. In Wen-Lian Hsu, Der-Tsai Lee, and Chung-Shou Liao, editors, 29th International Symposium on Algorithms and Computation, ISAAC 2018, December 16-19, 2018, Jiaoxi, Yilan, Taiwan, volume 123 of LIPIcs, pages 37:1–37:13. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2018. doi:10.4230/LIPIcs.ISAAC.2018.37.
  • [27] Michael J. Pelsmajer. Equitable list coloring and treewidth. J. Graph Theory, 61(2):127–139, 2009. doi:10.1002/jgt.20373.
  • [28] Alexa Sharp. Distance coloring. In Lars Arge, Michael Hoffmann, and Emo Welzl, editors, Algorithms – ESA 2007, 15th Annual European Symposium, Eilat, Israel, October 8-10, 2007, Proceedings, volume 4698 of Lecture Notes in Computer Science, pages 510–521. Springer, 2007. doi:10.1007/978-3-540-75520-3_46.
  • [29] Riste Skrekovski. Choosability of K5-minor-free graphs. Discret. Math., 190(1-3):223–226, 1998. doi:10.1016/S0012-365X(98)00158-7.
  • [30] Michael D. Smith, Norman Ramsey, and Glenn H. Holloway. A generalized algorithm for graph-coloring register allocation. In William W. Pugh and Craig Chambers, editors, Proceedings of the ACM SIGPLAN 2004 Conference on Programming Language Design and Implementation 2004, Washington, DC, USA, June 9-11, 2004, pages 277–288. ACM, 2004. doi:10.1145/996841.996875.
  • [31] Anthony Widjaja To. Parikh images of regular languages: Complexity and applications. CoRR, 2010. arXiv:1002.1464.
  • [32] Margit Voigt. List colourings of planar graphs. Discret. Math., 120(1-3):215–219, 1993. doi:10.1016/0012-365X(93)90579-I.
  • [33] D.R. Woodall. List colourings of graphs, pages 269–301. London Mathematical Society Lecture Note Series. Cambridge University Press, 2001.