The typical structure of Gallai colorings and their extremal graphs
aa r X i v : . [ m a t h . C O ] A ug The typical structure of Gallai colorings and their extremal graphs
J´ozsef Balogh ∗ Lina Li † August 21, 2019
Abstract
An edge coloring of a graph G is a Gallai coloring if it contains no rainbow triangle. Weshow that the number of Gallai r -colorings of K n is (cid:0)(cid:0) r (cid:1) + o (1) (cid:1) n ). This result indicates thatalmost all Gallai r -colorings of K n use only 2 colors. We also study the extremal behavior ofGallai r -colorings among all n -vertex graphs. We prove that the complete graph K n admitsthe largest number of Gallai 3-colorings among all n -vertex graphs when n is sufficiently large,while for r ≥
4, it is the complete bipartite graph K ⌊ n/ ⌋ , ⌈ n/ ⌉ . Our main approach is based onthe hypergraph container method, developed independently by Balogh, Morris and Samotij aswell as by Saxton and Thomason, together with some stability results. An edge coloring of a graph G is a Gallai coloring if it contains no rainbow triangle, that is,no triangle is colored with three distinct colors. The term
Gallai coloring was first introducedby Gy´arf´as and Simonyi [ ], but this concept had already occurred in an important result ofGallai [ ] on comparability graphs, which can be reformulated in terms of Gallai colorings. It alsoturns out that Gallai colorings are relevant to generalizations of the perfect graph theorem [ ],and some applications in information theory [ ]. There are a variety of papers which considerstructural and Ramsey-type problems on Gallai colorings, see, e.g., [
14, 16, 17, 18, 25 ].Two important themes in extremal combinatorics are to enumerate discrete structures that havecertain properties and describe their typical properties. In this paper, we shall be concerned withGallai colorings from such an extremal perspective.
For an integer r ≥
3, an r -coloring is an edge coloring that uses at most r colors. By choosing twoof the r colors and coloring the edges of K n arbitrarily with these two colors, one can easily obtainthat the number of Gallai r -colorings of K n is at least (cid:18) r (cid:19) (cid:16) n ) − (cid:17) + r = (cid:18) r (cid:19) n ) − r ( r − . (1) ∗ Department of Mathematical Sciences, University of Illinois at Urbana-Champaign, IL, USA, and Moscow In-stitute of Physics and Technology, 9 Institutskiy per., Dolgoprodny, Moscow Region, 141701, Russian Federation.Research of the first author is partially supported by NSF Grants DMS-1500121, DMS-1764123 and Arnold O.Beckman Research Award (UIUC) Campus Research Board 18132 and the Langan Scholar Fund (UIUC). † Department of Mathematics, University of Illinois at Urbana-Champaign, Urbana, Illinois 61801, USA. Email:[email protected].
1f we further consider all Gallai r -colorings of K n using exactly 3 colors, red, green, and blue, inwhich the red color is used only once, the number of them is exactly (cid:18) n (cid:19) (cid:16) n ) − ( n − − (cid:17) . Combining with (1), for n sufficiently large, a trivial lower bound for the number of Gallai r -coloringsof K n is (cid:18)(cid:18) r (cid:19) + 2 − n (cid:19) n ) . (2)Motivated by a question of Erd˝os and Rothschild [ ] and the resolution by Alon, Balogh, Keevashand Sudakov [ ], Benevides, Hoppen and Sampaio [ ] studied the general problem of countingthe number of edge colorings of a graph that avoid a subgraph colored with a given pattern. Inparticular, they proved that the number of Gallai 3-colorings of K n is at most ( n − · n − ).At the same time, Falgas-Ravry, O’Connell, and Uzzell [ ] provided a weaker upper bound of theform 2 (1+ o (1)) ( n ), which is a consequence of the multi-color container theory. Very recently, Bastos,Benevides, Mota and Sau [ ] improved the upper bound to 7( n + 1)2( n ). Note that the gap betweenthe best upper bound and the trivial lower bound is a linear factor. We show that the lower boundis indeed closer to the truth, and this actually applies for any integer r . Our first main result is asfollows. Theorem 1.1.
For every integer r ≥ , there exists n such that for all n > n , the number ofGallai r -colorings of the complete graph K n is at most (cid:18)(cid:18) r (cid:19) + 2 − n n (cid:19) n ) . Given a class of graphs A , we denote A n the set of graphs in A of order n . We say that almostall graphs in A has property B iflim n →∞ |{ G ∈ A n : G has property B}||A n | = 1 . Recall that the number of Gallai r -colorings with at most 2 colors is (cid:0) r (cid:1) n ) − r ( r − r -colorings immediately follows from Theorem 1.1. Corollary 1.2.
For every integer r ≥ , almost all Gallai r -colorings of the complete graph are2-colorings. There have been considerable advances in edge coloring problems whose origin can be traced backto a question of Erd˝os and Rothschild [ ], who asked which n -vertex graph admits the largestnumber of r -colorings avoiding a copy of F with a prescribed colored pattern, where r is a positiveinteger and F is a fixed graph. In particular, the study for the extremal graph of Gallai colorings,that is the case when F is a triangle with rainbow pattern, has received attention recently. Agraph G on n vertices is Gallai r -extremal if the number of Gallai r -colorings of G is largest overall graphs on n vertices. For r ≥
5, the Gallai r -extremal graph has been determined by Hoppen,Lefmann and Odermann [
19, 20, 21 ]. 2 heorem 1.3. [ ] For all r ≥ and n ≥ , the only Gallai r -extremal graph of order n is thecomplete bipartite graph K ⌊ n/ ⌋ , ⌈ n/ ⌉ . Theorem 1.4. [ ] For all r ≥ , there exists n such that for all n > n , the only Gallai r -extremalgraph of order n is the complete bipartite graph K ⌊ n/ ⌋ , ⌈ n/ ⌉ . For the cases r ∈ { , } , several approximate results were given. Theorem 1.5. [ ] There exists n such that the following hold for all n > n .(i) For all δ > , if G is a graph of order n , then the number of Gallai -colorings of G is atmost (1+ δ ) n / . (ii) For all ξ > , if G is a graph of order n , and e ( G ) ≤ (1 − ξ ) (cid:0) n (cid:1) , then the number of Gallai -colorings of G is at most n ) . We remark that the part (i) of Theorem 1.5 was also proved in [ ], and the authors furtherprovided an upper bound for r = 4. Theorem 1.6. [ ] There exists n such that the following hold for all n > n . For all δ > , if G is a graph of order n , then the number of Gallai -colorings of G is at most (1+ δ ) n / . The above theorems show that for r ∈ { , } , the complete graph K n is not far from beingGallai r -extremal, while for r = 4, the complete bipartite graph K ⌊ n/ ⌋ , ⌈ n/ ⌉ is also close to beGallai r -extremal. Benevides, Hoppen and Sampaio [ ] made the following conjecture. Conjecture 1.7. [ ] The only Gallai -extremal graph of order n is the complete graph K n . For the case r = 4, Hoppen, Lefmann and Odermann [ ] believed that K ⌊ n/ ⌋ , ⌈ n/ ⌉ should bethe extremal graph. Conjecture 1.8. [ ] The only Gallai -extremal graph of order n is the complete bipartite graph K ⌊ n/ ⌋ , ⌈ n/ ⌉ . Using a similar technique as in Theorem 1.1, we prove an analogous result for dense non-completegraphs when r = 3. Theorem 1.9.
For < ξ ≤ , there exists n such that for all n > n the following holds. If G isa graph of order n , and e ( G ) ≥ (1 − ξ ) (cid:0) n (cid:1) , then the number of Gallai 3-colorings of G is at most · e ( G ) + 2 − n n n ) . Together with Theorem 1.5 and the lower bound (2), Theorem 1.9 solves Conjecture 1.7 forsufficiently large n . Theorem 1.10.
There exists n such that for all n > n , among all graphs of order n , the completegraph K n is the unique Gallai -extremal graph. Our third contribution is the following theorem.
Theorem 1.11.
For n, r ∈ N with r ≥ , there exists n such that for all n > n the followingholds. If G is a graph of order n , and e ( G ) > ⌊ n / ⌋ , then the number of Gallai r -colorings of G is less than r ⌊ n / ⌋ . We remark that for a graph G with e ( G ) = ⌊ n / ⌋ , which is not K ⌊ n/ ⌋ , ⌈ n/ ⌉ , G contains at leastone triangle. Therefore, the number of Gallai r -colorings of G is at most r ( r + 2( r − r e ( G ) − There exists n such that for all n > n , among all graphs of order n , the completebipartite graph K ⌊ n/ ⌋ , ⌈ n/ ⌉ is the unique Gallai -extremal graph. .3 Overview of the paper Combining Szemer´edi’s Regularity Lemma and the stability method was used at many earlier workson extremal problems, including Erd˝os-Rothchild type problems, see, e.g., [ 1, 2, 9, 20 ]. However,our main approach relies on the method of hypergragh containers, developed independently byBalogh, Morris and Samotij [ ] as well as by Saxton and Thomason [ ], and some stability resultsfor containers, which may be of independent interest to readers.The paper is organized as follows. First, in Section 2, we introduce some important definitionsand then state a container theorem which is applicable to colorings. In Section 3, we present akey enumeration result on the number of colorings with special restrictions, which will be usedrepeatedly in the rest of the paper. Then in Section 4, we study the stability behavior of thecontainers for the complete graph, and apply the multicolor container theorem to give an asymptoticupper bound for the number of Gallai r -colorings of the complete graph. In Section 5, we deal withthe Gallai 3-colorings of dense non-complete graphs; the idea is the same as in Section 4 exceptthat we need to provide a new stability result which is applicable to non-complete graphs.In the second half of the paper, that is, in Section 6, we study the Gallai r -colorings of non-complete graphs for r ≥ 4. When the underlying graph is very dense, that is, close to the completegraph, we apply the same strategy as in Section 4 for the case r = 4, where we prove a properstability result for containers. The case r ≥ , i.e. the edge density of the extremal graph, some new ideas are needed,and we also adopt a result of Bollob´as and Nikiforov [ ] on book graphs. For the rest of thegraphs whose edge densities are between + o (1) and − o (1), we use a supersaturation result oftriangle-free graphs given by Balogh, Bushaw, Collares, Liu, Morris, and Sharifzadeh [ ], and theabove results on Gallai r -colorings for both high density graphs and low density graphs.For a positive integer n , we write [ n ] = { , , . . . , n } . For a graph G and a set A ⊆ V ( G ), the induced subgraph G [ A ] is the subgraph of G whose vertex set is A and whose edge set consists of allof the edges with both endpoints in A . For two disjoint subsets A, B ⊆ V ( G ), the induced bipartitesubgraph G [ A, B ] is the subgraph of G whose vertex set is A ∪ B and whose edge set consists of all ofthe edges with one endpoint in A and the other endpoint in B . Denote by δ ( G ) the minimum degreeof G , and ∆( G ) the maximum degree of G . For a graph G and a vertex v ∈ V ( G ), let N G ( v ) bethe neighborhood of v , i.e. the set of vertices adjacent to v in G , and d G ( v ) = | N G ( v ) | be the degree of v . For a set A ⊆ V ( G ), the neighborhood of v restricted to A is the set N G ( v, A ) = N G ( v ) ∩ A ;the degree of v restricted to A , denoted by d G ( v, A ), is the size of N G ( v, A ). When the underlyinggraph is clear, we simply write N ( v ), d ( v ), N ( v, A ), and d ( v, A ) instead. Throughout the paper, weomit all floor and ceiling signs whenever these are not crucial. Unless explicitly stated, all n -vertexgraphs are assumed to be defined on the vertex set [ n ], and all logarithms have base 2. We use the following version of the hypergraph container theorem (Theorem 3.1 in [ ]). Let H bea k -uniform hypergraph with average degree d . The co-degree of a set of vertices S ⊆ V ( H ) is thenumber of edges containing S ; that is, d ( S ) = { e ∈ E ( H ) | S ⊆ e } . ≤ j ≤ k , the j -th maximum co-degree of H is∆ j ( H ) = max { d ( S ) | S ⊆ V ( H ) , | S | = j } . When the underlying hypergraph is clear, we simply write it as ∆ j . For 0 < τ < 1, the co-degreefunction ∆( H , τ ) is defined as ∆( H , τ ) = 2( k ) − k X j =2 − ( j − ) ∆ j dτ j − . In particular, when k = 3, ∆( H , τ ) = 4∆ dτ + 2∆ dτ . Theorem 2.1. [ ] Let H be a k -uniform hypergraph on vertex set [ N ] . Let < ε, τ < / .Suppose that τ < / (200 k ! k ) and ∆( H , τ ) ≤ ε/ (12 k !) . Then there exists c = c ( k ) ≤ k ! k anda collection of vertex subsets C such that (i) every independent set in H is a subset of some A ∈ C ; (ii) for every A ∈ C , e ( H [ A ]) ≤ ε · e ( H ) ; (iii) log |C| ≤ cN τ log(1 /ε ) log(1 /τ ) . A key tool in applying container theory to multi-colored structures will be the notion of a template .This notion of ‘template’, which was first introduced in [ ], goes back to [ ] under the name of‘2-colored multigraphs’ and later to [ ], where it is simply called ‘containers’. For more studiesabout the multi-color container theory, we refer the interested reader to [ 4, 5, 7, 13, 24 ]. Definition 2.2 (Template and palette) . An r -template of order n is a function P : E ( K n ) → [ r ] ,associating to each edge e of K n a list of colors P ( e ) ⊆ [ r ]; we refer to this set P ( e ) as the palette available at e . Definition 2.3 (Subtemplate) . Let P , P be two r -templates of order n . We say that P is a subtemplate of P (written as P ⊆ P ) if P ( e ) ⊆ P ( e ) for every edge e ∈ E ( K n ).We observe that for G ⊆ K n , an r -coloring of G can be considered as an r -template of order n , with only one color allowed at each edge of G and no color allowed at each non-edge. For an r -template P , write RT( P ) for the number of subtemplates of P that are rainbow triangles. Wesay that P is rainbow triangle-free if RT( P ) = 0. Using the container method, Theorem 2.1, weobtain the following. Theorem 2.4. For every r ≥ , there exists a constant c = c ( r ) and a collection C of r -templatesof order n such that (i) every rainbow triangle-free r -template of order n is a subtemplate of some P ∈ C ; (ii) for every P ∈ C , RT( P ) ≤ n − / (cid:0) n (cid:1) ; (iii) |C| ≤ cn − / log n ( n ) . roof. Let H be a 3-uniform hypergraph with vertex set E ( K n ) × { , , . . . , r } , whose edges areall triples { ( e , d ) , ( e , d ) , ( e , d ) } such that e , e , e form a triangle in K n and d , d , d are alldifferent. In other words, every hyperedge in H corresponds to a rainbow triangle of K n . Note thatthere are exactly r ( r − r − 2) ways to rainbow color a triangle with r colors. Hence, the averagedegree d of H is equal to d = 3 e ( H ) v ( H ) = 3 r ( r − r − (cid:0) n (cid:1) r (cid:0) n (cid:1) = ( r − r − n − . For the application of Theorem 2.1, let ε = n − / /r ( r − r − 2) and τ = √ · · rn − / . Observethat ∆ ( H ) = r − 2, and ∆ ( H ) = 1. For n sufficiently large, we have τ ≤ / (200 · · 3) and∆( H , τ ) = 4( r − dτ + 2 dτ ≤ dτ ≤ ε · . Hence, there is a collection C of vertex subsets satisfying properties (i)-(iii) of Theorem 2.1. Observethat every vertex subset of H corresponds to an r -template of order n ; every rainbow triangle-free r -template of order n corresponds to an independent set in H . Therefore, C is a desired collectionof r -templates. Definition 2.5 (Gallai r -template) . For a graph G of order n , an r -template P of order n is a Gallai r -template of G if it satisfies the following properties:(i) for every e ∈ E ( G ), | P ( e ) | ≥ P ) ≤ n − / (cid:0) n (cid:1) . For a graph G of order n and a collection P of r -templates of order n , denote by Ga( P , G )the set of Gallai r -colorings of G which is a subtemplate of some P ∈ P . If P consists of a singletemplate P , then we simply write it as Ga( P, G ). In this section, we provide a lemma that will be useful to us in what follows. We use a special caseof the weak Kruskal-Katona theorem due to Lov`asz’s [ ]. Theorem 2.6 (Lov`asz [ ]) . Suppose G is a graph with (cid:0) x (cid:1) edges, for some real number x ≥ .Then the number of triangles of G is at most (cid:0) x (cid:1) , with equality if and only if x is an integer and G = K x . Lemma 2.7. Let n, r ∈ N with r ≥ and n − n ≤ ε < . If G is an r -colored graph of order n ,which contains at least (1 − ε ) (cid:0) n (cid:1) monochromatic triangles, then there exists a color c such that thenumber of edges colored by c is at least e ( G ) − r ε (cid:0) n (cid:1) .Proof. We shall prove this lemma by contradiction. Let δ = 4 r ε . Assume that none of the colorsis used on at least e ( G ) − δ (cid:0) n (cid:1) edges.First, we conclude that e ( G ) ≥ (1 − ε ) (cid:0) n (cid:1) . If not, then by Theorem 2.6, the number of trianglesof G is less than √ 23 (1 − ε ) / (cid:18) n (cid:19) / ≤ (1 − ε ) (cid:18) n (cid:19) , which contradicts the assumption. 6y the pigeonhole principle, we can assume without loss of generality that the set of red edgesin G , denoted by R( G ), satisfies | R( G ) | ≥ (1 − ε ) (cid:0) n (cid:1) /r. By the contradiction assumption, wehave | R( G ) | < e ( G ) − δ (cid:0) n (cid:1) . Therefore, the number of non-red edges is greater than δ (cid:0) n (cid:1) . Again,without loss of generality, we can assume that the set of blue edges in G , denoted by B( G ), satisfies | B( G ) | ≥ δ (cid:0) n (cid:1) /r. For an edge in R( G ) and an edge in B( G ), these two edges either share one endpoint or arevertex disjoint, see Figure 1. In the first case, see Figure 1a, the triple abc could not form amonochromatic triangle of G . In the latter case, see Figure 1b, at least one of abc and bcd is not amonochromatic triangle of G . ab cred blue (a) ab cdred blue (b) Figure 1: Two cases of a red-blue pair of edges.Let NT( G ) be the family of triples { a, b, c } which does not form a monochromatic triangle of G . The above discussion shows that each pair of red and blue edges generates at least one triplein NT( G ). Observe that each triple in NT( G ) can be counted in at most 2 + 3( n − 3) pairs of redand blue edges. Hence, we obtain that | NT( G ) | ≥ (1 − ε ) (cid:0) n (cid:1) /r · δ (cid:0) n (cid:1) /r n − > δ r (cid:18) n (cid:19) = ε (cid:18) n (cid:19) , which contradicts the assumption of the lemma. r -templates In this section, we aim to prove the following technical theorem, which will be used repeatedly inthe rest of the paper. Theorem 3.1. Let n, r ∈ N with r ≥ , and G be a graph of order n . Suppose that δ = log − n and k is a positive constant, which does not depend on n . For two colors i , j ∈ [ r ] , denote by F = F ( i, j ) the set of r -templates of order n , which contain at least (1 − kδ ) (cid:0) n (cid:1) edges with palette { i, j } . Then, for n sufficiently large, | Ga( F , G ) | ≤ e ( G ) + 2 − n n n ) . Fix two colors 1 ≤ i < j ≤ r , and let S = [ r ] − { i, j } . For an r -coloring F of G , let S ( F ) bethe set of edges in G , which are colored by colors in S . From the definition of F , we immediatelyobtain the following proposition. Proposition 3.2. For every F ∈ Ga( F , G ) , the number of edges in S ( F ) is at most kδ (cid:0) n (cid:1) . emma 3.3. Let F be the set of F ∈ Ga( F , G ) such that S ( F ) contains a matching of size δn log n . Then, for n sufficiently large, |F | ≤ − n 25 log9 n n ) . Proof. Let us consider the ways to color G so that the resulting colorings are in F . We first choosethe set of edges E S which will be colored by the colors in S . Note that E S must contain a matchingof size δn log n by the definition of F . By Proposition 3.2, there are at most P i ≤ kδ ( n ) (cid:0) ( n ) i (cid:1) choices for such E S , and the number of ways to color them is at most r kδ ( n ) . In the next step,take a matching M of size δn log n in E S ; the number of ways to choose such matching is at most (cid:0) ( n ) δn log n (cid:1) .Let A = V ( M ) and B = [ n ] \ A . Denote by T the set of triangles of K n with a vertex in B and an edge from M , which contain no edge in E S ∩ G [ A, B ]. We claim that |T | ≥ δn log n asotherwise we would obtain that | E S | ≥ | B | · δn log n − |T | + | M | ≥ δn log n − δn log n = 14 δn log n > kδ (cid:18) n (cid:19) , which, by Proposition 3.2, contradicts the fact that F ∈ Ga( F , G ). Note that if a triangle T in T contains more than one uncolored edge, then they must have the same color in order to avoid therainbow triangle. Hence, the number of ways to color the uncolored edges in T is at most 2 |T | .There remain at most (cid:0) n (cid:1) − |T | uncolored edges and they can only be colored by i or j , asedges in E S are already colored. Hence, the number of ways to color the rest of edges is at most2( n ) − |T | . In conclusion, we obtain that |F | ≤ P i ≤ kδ ( n ) (cid:0) ( n ) i (cid:1) r kδ ( n ) (cid:0) ( n ) δn log n (cid:1) · |T | · n ) − |T | ≤ O ( δn log n ) · O ( δn log n ) · n ) − δn log n ≤ n ) − n 25 log9 n . Lemma 3.4. For every integer ≤ t < δn log n , let F ( t ) be the set of F ∈ Ga( F , G ) , in whichthe maximum matching of S ( F ) is of size t . Then, for n sufficiently large, |F ( t ) | ≤ − n n n ) . Proof. For a fixed t , let us count the ways to color G so that the resulting colorings are in F ( t ).By the definition of F ( t ), among all edges which will be colored by the colors in S , there exists amaximum matching M of size t . We first choose such matching; the number of ways is at most (cid:0) ( n ) t (cid:1) . Once we fix the matching M , let A = V ( M ) and B = [ n ] \ A . By the maximality of M , weimmediately obtain the following claim. Claim 1. None of the edges in G [ B ] can be colored by the colors in S . Denote by Cr( S ) the set of edges in G [ A, B ] which will be colored by the colors in S . For avertex u ∈ A , denote by Cr( S, u ) the set of edges in Cr( S ) with one endpoint u . Similarly, defineCr( { i, j } , u ) to be the set of edges in G [ u, B ] which will be colored by the colors i or j . We shalldivide the proof into three cases. 8 ase 1 : | Cr( S ) | ≤ nt log n .We first color the edges in G [ A ] and the number of options is at most r ( t ). In the next step,we select and color the edges in Cr( S ); by the above inequality, the number of ways is at most P i ≤ nt log2 n (cid:0) nti (cid:1) r nt log2 n . By Claim 1, the remaining edges can only use the colors i or j . Let T bethe set of triangles of K n formed by a vertex in B and an edge from M , which contain no edge inCr( S ). We claim that |T | ≥ nt as otherwise we would obtain | Cr( S ) | ≥ | B | t − |T | ≥ nt − nt > nt log n , which contradicts the assumption. If a triangle T in T contains more than one uncolored edge,then they must have the same color in order to avoid the rainbow triangle. Hence, the number ofways to color the uncolored edges in T is at most 2 |T | .There remain at most (cid:0) n (cid:1) − |T | − (cid:0) t (cid:1) uncolored edges, and they can be colored by i or j .Therefore the number of ways to color the rest of the edges is at most 2( n ) − |T |− ( t ) . In conclusion,we obtain that the number of r -coloring F ∈ F ( t ) with | Cr( S ) | ≤ nt log n is at most (cid:18)(cid:0) n (cid:1) t (cid:19) · r ( t ) · P i ≤ nt log2 n (cid:0) nti (cid:1) r nt log2 n · |T | · n ) − |T |− ( t ) ≤ O ( t log n ) · O ( t ) · O (cid:16) nt log n (cid:17) · n ) − nt ≤ n ) − nt ≤ n ) − n , where the third inequality is given by t ≤ t · δn log n = nt/ log n. Case 2 : There exists a vertex u ∈ A such that | Cr( S, u ) | ≥ n log n and | Cr( { i, j } , u ) | ≥ n log n . (3)We first choose the vertex u , and the number of options is at most 2 t . Moreover, the numberof ways to select and color edges in Cr( S, u ) is at most r n n . In the next step, we color all theuncolored edges in G [ A, B ] and G [ A ], and the number of ways is at most r nt + ( t ). Let T be theset of triangles T = { uvw } of K n , in which v, w ∈ B , uv ∈ Cr( S, u ), and uw ∈ Cr( { i, j } , u ). Bythe relation (3), we have |T | ≥ n log n . For every triangle T = { uvw } ∈ T , if vw is an edge of G ,then by Claim 1 it can only be colored by i or j , and must have the same color with uw in order toavoid the rainbow triangle. Therefore, the number of ways to color the uncolored edges in T is 1.There remain at most (cid:0) n (cid:1) − |T | uncolored edges in B , as other edges are already colored. ByClaim 1, none of the remaining edges in B could use the colors from S . Therefore, the numberof ways to color the rest of edges is at most 2( n ) −|T | . In conclusion, we obtain that the number of F ∈ F ( t ) which is included in Case 2 is at most (cid:18)(cid:0) n (cid:1) t (cid:19) · t · r n n · r nt + ( t ) · n ) −|T | ≤ O ( t log n ) · O ( n ) · O ( nt ) · n ) − n n ≤ n ) − n 22 log8 n , where the last inequality is given by the condition that nt ≤ n · δn log n = n / log n. Case 3: | Cr( S ) | > nt log n , and for every vertex u ∈ A , | Cr( S, u ) | < n log n or | Cr( { i, j } , u ) | < n log n . (4)9e first color the edges in G [ A ] and the number of ways is at most r ( t ). By (4), for every vertex u ∈ A , the number of ways to select Cr( S, u ) is at most 2 P i ≤ n/ log n (cid:0) ni (cid:1) ≤ n/ log n . Therefore,the number of ways to select Cr( S ) is at most 2 nt/ log n . Subcase 3.1: e ( G ) ≤ (cid:0) n (cid:1) − n n . The number of ways to color Cr( S ) is at most r nt . By Claim 1, the rest of the edges can onlybe colored by i or j , and the number of them is at most e ( G ) − | Cr( S ) | . Hence, the number of F ∈ F ( t ) covered in Case 3.1 is at most (cid:18)(cid:0) n (cid:1) t (cid:19) · r ( t ) · nt log3 n · r nt · e ( G ) −| Cr( S ) | ≤ O ( t log n ) · O ( nt ) · n ) − n 24 log6 n − nt log2 n ≤ n ) − n 25 log6 n , where the last inequality holds by the condition that nt ≤ n · δn log n = n / log n. Subcase 3.2: e ( G ) > (cid:0) n (cid:1) − n n . For u ∈ A , define N S ( u ) = { v ∈ B | uv ∈ Cr( S, u ) } . Let G u be the induced subgraph of G on N S ( u ), and denote by c ( G u ) the number of components of G u . Claim 2. For every u ∈ A , we have c ( G u ) ≤ n log n .Proof. Suppose that there exists a vertex u in A with c ( G u ) > n log n . Then the number of non-edgesin G u is at least (cid:0) n log3 n (cid:1) ≥ n n , which contradicts with the assumption of Case 3.2. Claim 3. For every u ∈ A , the number of ways to color Cr( S, u ) is at most r c ( G u ) .Proof. Let C be an arbitrary component of G u . It is sufficient to prove that for every v, w ∈ V ( C ), uv and uw must have the same color. Assume that there exist v, w ∈ V ( C ) such that uv and uw receive different colors. Since C is a connected component of G u , there is a path P = { v = v , v , v , . . . , v k = w } in G u , in which uv i is painted by a color in S for every 0 ≤ i ≤ k . Moreover,since uv and uw receive different colors, there exists an integer 0 ≤ j ≤ k − uv j and uv j +1 receive different colors. On the other hand, by Claim 1, v j v j +1 can only be colored by i or j . Therefore, u, v j , v j +1 form a rainbow triangle, which is not allowed in a Gallai r -coloring.By Claims 2 and 3, the number of ways to color Cr( S, u ) is at most r n log3 n , and therefore thetotal number of ways to color Cr( S ) is at most r nt log3 n . By Claim 1, the rest of the edges can onlybe colored by i or j , and the number of them is at most e ( G ) − | Cr( S ) | . Hence, the number of F ∈ F ( t ) included in Case 3.2 is at most (cid:18)(cid:0) n (cid:1) t (cid:19) · r ( t ) · nt log3 n · r nt log3 n · e ( G ) −| Cr( S ) | ≤ O ( t log n ) · O (cid:16) nt log3 n (cid:17) · n ) − nt log2 n ≤ n ) − n n − . Eventually, we conclude that |F ( t ) | ≤ n ) − n + 2( n ) − n 22 log8 n + 2( n ) − n n − ≤ − n n n )for every 1 ≤ t < δn log n .Observe that every r -coloring of G using at most 2 colors is a Gallai r -coloring. Then weimmediately obtain the following lemma. Lemma 3.5. Let F be the set of F ∈ Ga( F , G ) such that S ( F ) = ∅ . Then |F | = 2 e ( G ) . Proof of Theorem 3.1. Applying Lemmas 3.3, 3.4 and 3.5, we obtain that | Ga( F , G ) | = |F | + δn/ log n X t =1 |F ( t ) | + |F | ≤ e ( G ) + 2 − n n n ) , for n sufficiently large. r -colorings of complete graphs r -template of complete graphs Proposition 4.1. Let n , r ∈ N with r ≥ . Suppose P is a Gallai r -template of K n . Then thenumber of edges with at least 3 colors in its palette is at most n − / n .Proof. Let E = { e ∈ E ( K n ) : | P ( e ) | ≥ } and assume that | E | > n − / n . Let F be a spanningsubgraph of K n with edge set E . For every i ∈ [ n ], denote by d i the degree of vertex i of F . Thenthe number of 3-paths in F is equal to X i ∈ [ n ] (cid:18) d i (cid:19) ≥ n (cid:18) P i ∈ [ n ] d i n (cid:19) ≥ n (cid:18) | E | /n (cid:19) ≥ | E | n > n − / (cid:18) n (cid:19) . Observe that if i, j, k is a 3-path in F , then there is at least one rainbow triangle in P with vertexset { i, j, k } since edges ij , jk have at least 3 colors in its palette and edge ik has at least onecolor in its palette. Therefore, there would be more than n − / (cid:0) n (cid:1) rainbow triangles in P , whichcontradicts the fact that P is a Gallai r -template. Lemma 4.2. Let n , r ∈ N with r ≥ and n − / ≪ δ ≪ . Assume that P is a Gallai r -templateof K n with | Ga( P, K n ) | > (1 − δ ) ( n ) . Then the number of triangles T of K n with P e ∈ T | P ( e ) | = 6 and P ( e ) = P ( e ′ ) for every e , e ′ ∈ T is at least (1 − δ ) (cid:0) n (cid:1) .Proof. Let T be the collection of triangles of K n . We define T = (cid:8) T ∈ T | P e ∈ T | P ( e ) | = 6 and P ( e ) = P ( e ′ ) for every e, e ′ ∈ T (cid:9) , T = { T ∈ T | ∃ e ∈ T, | P ( e ) | ≥ } , T = (cid:8) T ∈ T \ ( T ∪ T ) | P e ∈ T | P ( e ) | = 6 (cid:9) , T = (cid:8) T ∈ T \ T | P e ∈ T | P ( e ) | ≤ (cid:9) . Let |T | = α (cid:0) n (cid:1) , |T | = β (cid:0) n (cid:1) , |T | = γ (cid:0) n (cid:1) . Then |T | ≤ (1 − α ) (cid:0) n (cid:1) . By Proposition 4.1, we have |T | ≤ n − / n and therefore β ≤ n − / . Observe that for every T ∈ T , the template P containsa rainbow triangle with edge set T ; therefore, we obtain that |T | ≤ RT( P ) ≤ n − / (cid:0) n (cid:1) , which gives γ ≤ n − / ≤ n − / .Assume that α < − δ . Then the number of Gallai r -colorings of K n , which are subtemplatesof P , satisfieslog | Ga( P, K n ) | ≤ log (cid:16)Q e ∈ E ( K n ) | P ( e ) | (cid:17) = log (cid:0)Q T ∈T Q e ∈ T | P ( e ) | (cid:1) n − ≤ log (cid:0)Q T ∈T Q T ∈T r Q T ∈T Q T ∈T (cid:1) · n − ≤ (3 α + 3 β log r + 3 γ + 2(1 − α )) (cid:0) n (cid:1) ≤ (cid:0) α + (36 log r + 3) n − / (cid:1) (cid:0) n (cid:1) < (2 + (1 − δ ) + δ ) (cid:0) n (cid:1) = (1 − δ ) (cid:0) n (cid:1) . | Ga( P, K n ) | > (1 − δ ) ( n ).We now prove a stability result for Gallai r -templates of K n . Theorem 4.3. Let n , r ∈ N with r ≥ and n − / ≪ δ ≪ . Assume that P is a Gallai r -templateof K n with | Ga( P, K n ) | > (1 − δ ) ( n ) . Then there exist two colors i , j ∈ [ r ] such that the number ofedges of K n with palette { i, j } is at least (1 − r δ ) (cid:0) n (cid:1) .Proof. Let G be an (cid:0) r (cid:1) -colored graph with edge set E ( G ) = { e ∈ E ( K n ) | | P ( e ) | = 2 } and colorset { ( i, j ) | ≤ i < j ≤ r } , where each edge e is colored by color P ( e ). By Lemma 4.2, thenumber of monochromatic triangles in G is at least (1 − δ ) (cid:0) n (cid:1) . Applying Lemma 2.7 on G , weobtain that there exist two colors i , j such that the number of edges with palette { i, j } is at least e ( G ) − (cid:0) r (cid:1) · δ (cid:0) n (cid:1) ≥ (1 − δ ) (cid:0) n (cid:1) − (cid:0) r (cid:1) · δ (cid:0) n (cid:1) ≥ (1 − r δ ) (cid:0) n (cid:1) . Proof of Theorem 1.1. Let C be the collection of containers given by Theorem 2.4. We observe thata Gallai r -coloring of K n can be regarded as a rainbow triangle-free r -coloring template of order n ,with only one color allowed at each edge. Therefore, by Property (i) of Theorem 2.4, every Gallai r -coloring of K n is a subtemplate of some P ∈ C .Let δ = log − n . We define C = n P ∈ C : | Ga( P, K n ) | ≤ (1 − δ ) ( n ) o , C = n P ∈ C : | Ga( P, K n ) | > (1 − δ ) ( n ) o . By Property (iii) of Theorem 2.4, we have | Ga( C , K n ) | ≤ |C | · (1 − δ ) ( n ) ≤ cn − / log n ( n ) · n ) − log − n ( n ) ≤ − n 24 log11 n n ) . We claim that every template P in C is a Gallai r -template of K n . First, by Property (ii)of Theorem 2.4, we have RT( P ) ≤ n − / (cid:0) n (cid:1) . Suppose that there exists an edge e ∈ E ( K n ) with | P ( e ) | = 0. Then we would obtain Ga( P, K n ) = ∅ as a Gallai r -coloring of K n requires at leastone color on each edge, which contradicts the definition of C . Now by Theorem 4.3, we can divide C into classes {F i,j , ≤ i < j ≤ r } , where F i,j consists of all the r -templates in C which containat least (1 − r δ ) (cid:0) n (cid:1) edges with palette { i, j } . Applying Theorem 3.1 on F i,j , we obtain that | Ga( F i,j , K n ) | ≤ (cid:16) − n n (cid:17) n ), and therefore | Ga( C , K n ) | ≤ X ≤ i Let n, r ∈ N with r ≥ and < k ≤ . For < ξ ≤ (cid:16) k k (cid:17) , let G be a graph oforder n , and e ( G ) ≥ (1 − ξ ) (cid:0) n (cid:1) . Assume that P is a Gallai r -template of G . Then, for sufficientlylarge n , |T ( P ) | ≤ max (cid:26) k |T ( P ) | , kk n − (cid:18) n (cid:19)(cid:27) . Proof. Let E = { e ∈ E ( K n ) : | P ( e ) | ≥ } and F be a spanning subgraph of K n with edge set E .For every i ∈ [ n ], denote by d i the degree of vertex i of F . Since P ni =1 d i = 2 | E | , the number ofvertices with d i > √ ξn is less than | E |√ ξn . Therefore, we obtain |T ( P ) | ≤ n X i =1 min (cid:26)(cid:18) d i (cid:19) , ξ (cid:18) n (cid:19)(cid:27) < | E |√ ξn · ξn X d i ≤√ ξn d i ≤ | E |√ ξn · ξn | E |√ ξn · ξn | E | p ξn ≤ k k n | E | , (6)where the third inequality follows from the concavity of the function x . The rest of the proof isdivided into two cases. Case 1 : | E | ≥ kk n − (cid:0) n (cid:1) .Consider all triangles of K n with at least one edge in E . Note that if a triangle has at least one edgein E and belongs to neither T ( P ) nor T ( P ), then it induces a rainbow triangle in P . Togetherwith (6), we have k |T ( P ) | ≥ k (cid:16) | E | ( n − − |T ( P ) | − n − (cid:0) n (cid:1)(cid:17) ≥ k (cid:16) k k n | E | − | E | − n − (cid:0) n (cid:1)(cid:17) = k k n | E | + k (cid:16) k k n | E | − | E | − n − (cid:0) n (cid:1)(cid:17) ≥ k k n | E | ≥ |T ( P ) | , where the fourth inequality is given by | E | ≥ kk n − (cid:0) n (cid:1) for sufficiently large n . Case 2 : | E | < kk n − (cid:0) n (cid:1) .In this case, we have |T ( P ) | < | E | ( n − < kk n − / (cid:18) n (cid:19) . .2 Stability of Gallai -templates of dense non-complete graphs Lemma 5.2. Let < ξ ≤ and n − / ≪ δ ≪ . Let G be a graph of order n , and e ( G ) ≥ (1 − ξ ) (cid:0) n (cid:1) . Assume that P is a Gallai -template of G with | Ga( P, G ) | > (1 − δ ) ( n ) . Then |T ( P ) | ≥ (1 − δ ) (cid:0) n (cid:1) .Proof. Let |T ( P ) | = α (cid:0) n (cid:1) , |T ( P ) | = β (cid:0) n (cid:1) , |T ( P ) | = η (cid:0) n (cid:1) and |T ( P ) | = γ (cid:0) n (cid:1) . Then |T ( P ) | ≤ (1 − α − β − η ) (cid:0) n (cid:1) . Observe that for every T ∈ T ( P ), the template P contains a rainbow trianglewith edge set T ; therefore, we obtain that |T ( P ) | ≤ RT ( P ) ≤ n − / (cid:0) n (cid:1) , which gives γ ≤ n − / .Define for e ∈ E ( K n ) the weight function w ( e ) = ( P ( e ) = ∅ , | P ( e ) | otherwise . Similarly to the proof of Lemma 4.2, the number of Gallai 3-colorings of G which are subtemplatesof P satisfieslog | Ga( P, G ) | ≤ log (cid:0)Q e ∈ K n | w ( e ) | (cid:1) = log (cid:0)Q T ∈T Q e ∈ T | w ( e ) | (cid:1) n − ≤ log (cid:0)Q T ∈T Q T ∈T Q T ∈T Q T ∈T Q T ∈T (cid:1) · n − ≤ (3 α + 2 β log 3 + η log 6 + 3 γ log 3 + 2(1 − α − β − η )) (cid:0) n (cid:1) = (cid:0) α + (2 log 3 − β + (log 6 − η + 3 n − / log 3 (cid:1) (cid:0) n (cid:1) . (7)Let k = 1. By Lemma 5.1, we have β ≤ max { η, n − / } . Assume that α < − δ . The restof the proof shall be divided into two cases. Case 1 : β ≤ η .If η < δ , continuing (7) we havelog | Ga( P, G ) | ≤ (cid:0) α + (2 log 3 + log 6 − η + 3 n − / log 3 (cid:1) (cid:0) n (cid:1) ≤ (2 + (1 − δ ) + 1 . · δ + δ ) (cid:0) n (cid:1) = (1 − δ ) (cid:0) n (cid:1) . Otherwise, together with α ≤ − β − η , continuing (7) we obtain thatlog | Ga( P, G ) | ≤ (cid:0) − β + (log 6 − η + 3 n − / log 3 (cid:1) (cid:0) n (cid:1) ≤ (cid:0) − η + 3 n − / log 3 (cid:1) (cid:0) n (cid:1) ≤ (3 − . · δ + δ ) (cid:0) n (cid:1) = (1 − δ ) (cid:0) n (cid:1) . Case 2 : β ≤ n − / .Together with η ≤ − α and α < − δ , continuing (7) we havelog | Ga( P, G ) | ≤ (cid:0) α + 2 log 3 · n − / + (log 6 − − α ) + 3 n − / log 3 (cid:1) (cid:0) n (cid:1) ≤ (cid:0) log 6 + (3 − log 6) α + 27 n − / log 3 (cid:1) (cid:0) n (cid:1) ≤ (log 6 + (3 − log 6)(1 − δ ) + δ ) (cid:0) n (cid:1) < (1 − δ ) (cid:0) n (cid:1) . Both cases contradict our assumption that | Ga( P, G ) | > (1 − δ ) ( n ).Similarly as in the proof of Theorem 4.3, using Lemmas 2.7 and 5.2, we obtain the followingtheorem. Theorem 5.3. Let < ξ ≤ and n − / ≪ δ ≪ . Let G be a graph of order n and e ( G ) ≥ (1 − ξ ) (cid:0) n (cid:1) . Assume that P is a Gallai -template of G with | Ga( P, G ) | > (1 − δ ) ( n ) . Then there existtwo colors i , j ∈ [3] such that the number of edges of K n with palette { i, j } is at least (1 − · δ ) (cid:0) n (cid:1) . .3 Proof of Theorem 1.9 Proof of Theorem 1.9. Let C be the collection of containers given by Theorem 2.4 for r = 3. Notethat every Gallai 3-coloring of G is a subtemplate of some P ∈ C . Let δ = log − n . We define C = n P ∈ C : | Ga( P, K n ) | ≤ (1 − δ ) ( n ) o , C = n P ∈ C : | Ga( P, K n ) | > (1 − δ ) ( n ) o . Similarly to the proof of Theorem 1.1, applying Theorems 2.4, 3.1, and 5.3, we obtain that | Ga( C , G ) | = | Ga( C , G ) | + | Ga( C , G ) | ≤ − n 24 log11 n n ) + 3 · (cid:16) e ( G ) + 2 − n n n ) (cid:17) ≤ · e ( G ) + 2 − n n n ) . r -colorings of non-complete graphs Theorem 1.11 is a direct consequence of the following three theorems. Theorem 6.1. For n, r ∈ N with r ≥ , there exists n such that for all n > n the following holds.For a graph G of order n with e ( G ) ≥ (1 − log − n ) (cid:0) n (cid:1) , the number of Gallai r -colorings of G isstrictly less than r ⌊ n / ⌋ . Theorem 6.2. Let n, r ∈ N with r ≥ , and < ξ ≪ . For a graph G of order n with ⌊ n / ⌋ < e ( G ) ≤ ⌊ n / ⌋ + ξn , the number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ . Theorem 6.3. For n, r ∈ N with r ≥ , there exists n such that for all n > n the following holds.Let n − / ≪ ξ ≤ log − n ≪ . For a graph G of order n with ( + 3 ξ ) n ≤ e ( G ) ≤ ( − ξ ) n ,the number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ . r ≥ Lemma 6.4. Let n, r ∈ N with r ≥ and < ξ ≤ . Assume that G is a graph of order n with e ( G ) ≥ (1 − ξ ) (cid:0) n (cid:1) , and P is a Gallai r -template of G . Then, for sufficiently large n , | Ga( P, G ) | ≤ r ( n ) · − . ( n ) . Proof. Let T be the collection of triangles of K n . For a given r -template P of order n , we againuse the partition (5). Let |T ( P ) | = α (cid:0) n (cid:1) , |T ( P ) | = β (cid:0) n (cid:1) , |T ( P ) | = η (cid:0) n (cid:1) and |T ( P ) | = γ (cid:0) n (cid:1) .Then |T ( P ) | ≤ (1 − α − β − η ) (cid:0) n (cid:1) . Note that for every T ∈ T ( P ), the template P contains arainbow triangle with edge set T ; therefore, we obtain that |T ( P ) | ≤ RT( P ) ≤ n − / (cid:0) n (cid:1) , whichgives γ ≤ n − / .Define for e ∈ E ( K n ) the weight function w ( e ) = ( P ( e ) = ∅| P ( e ) | otherwise . Similarly, as in Lemma 5.2, the number of Gallai r -colorings of G , which is a subtemplate of P ,satisfies log | Ga( P, G ) | ≤ log (cid:0)Q T ∈T Q T ∈T r Q T ∈T r Q T ∈T r Q T ∈T (cid:1) · n − ≤ (3 α + 2 β log r + η log 2 r + 3 γ log r + 2(1 − α − β − η )) (cid:0) n (cid:1) ≤ (cid:0) α + (2 log r − β + (log r − η + 3 n − / log r (cid:1) (cid:0) n (cid:1) . (8)15et k = 1 / 12. By Lemma 5.1, we have β ≤ max { kη, kk n − / } . The rest of the proof shall bedivided into two cases. Case 1 : β ≤ kη .Together with α ≤ (1 − β − η ), continuing (8) we havelog | Ga( P, G ) | ≤ (cid:0) r − β + (log r − η + 3 n − / log r (cid:1) (cid:0) n (cid:1) ≤ (cid:0) k + 1) log r − (3 k + 2)) η + 3 n − / log r (cid:1) (cid:0) n (cid:1) . Note that (2 k + 1) log r − (3 k + 2) is positive as r ≥ 4. Therefore, together with η ≤ k = ,we obtain thatlog | Ga( P, G ) | ≤ (cid:0) log r + + 3 n − / log r (cid:1) (cid:0) n (cid:1) ≤ (cid:0) log r − . 023 + 3 n − / log r (cid:1) (cid:0) n (cid:1) ≤ (cid:0) n (cid:1) log r − . (cid:0) n (cid:1) , where the second inequality follows from ( log r − ) ≥ . 023 as r ≥ Case 2 : β ≤ kk n − / .Together with α ≤ (1 − η ), continuing (8) we havelog | Ga( P, G ) | ≤ (cid:0) r − η + 2 log r · kk n − / + 3 n − / log r (cid:1) (cid:0) n (cid:1) ≤ (cid:0) log r − (cid:0) log r − (cid:1) + (cid:0) kk + 1 (cid:1) n − / log r (cid:1) (cid:0) n (cid:1) ≤ (cid:0) log r − . 16 + 0 . (cid:1) (cid:0) n (cid:1) = (cid:0) n (cid:1) log r − . (cid:0) n (cid:1) , where the third inequality holds for r ≥ n .Using Lemma 6.4, we prove a stronger theorem for the case r ≥ Theorem 6.5. For n, r ∈ N with r ≥ and < ξ ≤ , there exists n such that for all n > n the following holds. If G is a graph of order n , and e ( G ) ≥ (1 − ξ ) (cid:0) n (cid:1) , then the number of Gallai r -colorings of G is less than r ( n ) . Proof. Let C be the collection of containers given by Theorem 2.4. Theorem 2.4 indicates that everyGallai r -coloring of G is a subtemplate of some P ∈ C and |C| ≤ cn − / log n ( n ) for some constant c , which only depends on r . We may assume that all templates P in C are Gallai r -templates of G .By Property (ii) of Theorem 2.4, we always have RT( P ) ≤ n − / (cid:0) n (cid:1) . Suppose that for a template P there exists an edge e ∈ E ( G ) with | P ( e ) | = 0. Then we would obtain | Ga( P, G ) | = 0 as aGallai r -coloring of G requires at least one color on each edge. Now applying Lemma 6.4 on everycontainer P ∈ C , we obtain that the number of Gallai r -colorings of G is at most X P ∈C | Ga( P, G ) | ≤ |C| · r ( n ) · − . ( n ) < r ( n )for n sufficiently large. 16 .2 Proof of Theorem 6.1 for r = 4 Given two colors R and B , consider a 4-template P of order n in which every edge of K n haspalette { R, B } . For a constant 0 < ε ≪ G with e ( G ) > (cid:0) n (cid:1) − εn , we can easilycheck that P is a Gallai 4-template of G and | Ga( P, G ) | = 2 e ( G ) > ( n ) − εn . This indicates thatLemma 6.4 fails to hold when r = 4. Instead, we shall apply the same technique as for 3-colorings:prove a stability result to determine the approximate structure of r -templates, which would containtoo many Gallai r -colorings, and then apply this together with Theorem 3.1 to obtain the desiredbound. Lemma 6.6. Let n − / ≪ δ ≪ . Let G be a graph of order n with e ( G ) ≥ (1 − δ ) (cid:0) n (cid:1) . Assumethat P is a Gallai -template of G with | Ga( P, G ) | > (1 − δ ) ( n ) . Then the number of triangles T of K n with P e ∈ T | P ( e ) | = 6 and P ( e ) = P ( e ′ ) for every e , e ′ ∈ T is at least (1 − δ ) (cid:0) n (cid:1) .Proof. Let T be the collection of triangles of K n . We define T = (cid:8) T ∈ T | P e ∈ T | P ( e ) | = 6 and P ( e ) = P ( e ′ ) for every e, e ′ ∈ T (cid:9) , T = { T ∈ T | ∃ e ∈ T, | P ( e ) | = 0 } , T = { T ∈ T | T = { e , e , e } , | P ( e ) | = 4 , | P ( e ) | = | P ( e ) | = 1 } , T = (cid:8) T ∈ T \ ( T ∪ T ∪ T ) | P e ∈ T | P ( e ) | ≥ (cid:9) , T = (cid:8) T ∈ T \ T | P e ∈ T | P ( e ) | ≤ (cid:9) . Let |T | = α (cid:0) n (cid:1) , |T | = β (cid:0) n (cid:1) , |T | = η (cid:0) n (cid:1) and |T | = γ (cid:0) n (cid:1) . Then |T | = (1 − α − β − η − γ ) (cid:0) n (cid:1) .Since G satisfies e ( G ) ≥ (1 − δ ) (cid:0) n (cid:1) and P is a Gallai template, we have |T | ≤ δ (cid:0) n (cid:1) · n ≤ δ (cid:0) n (cid:1) , andtherefore β ≤ δ . Observe that for every T ∈ T , the template P contains a rainbow triangle withedge set T ; therefore, we obtain that |T | ≤ RT ( P ) ≤ n − / (cid:0) n (cid:1) , which gives γ ≤ n − / .Define for e ∈ E ( K n ) the weight function w ( e ) = ( P ( e ) = ∅| P ( e ) | otherwise . Assume that α < − δ . Similarly, as in Lemma 5.2, the number of Gallai 4-colorings of G whichis a subtemplate of P satisfieslog | Ga( P, G ) | ≤ log (cid:0)Q T ∈T Q T ∈T Q T ∈T Q T ∈T Q T ∈T (cid:1) · n − ≤ (3 α + 4 β + 2 η + 6 γ + 2(1 − α − β − η − γ )) (cid:0) n (cid:1) = (2 + α + 2 β + 4 γ ) (cid:0) n (cid:1) < (2 + (1 − δ ) + 13 δ ) (cid:0) n (cid:1) = (1 − δ ) (cid:0) n (cid:1) . This contradicts the assumption that | Ga( P, G ) | > (1 − δ ) ( n ).Similarly, as in Theorem 4.3, applying Lemmas 2.7 and 6.6, we obtain the following. Theorem 6.7. Let n − / ≪ δ ≪ . Let G be a graph of order n with e ( G ) ≥ (1 − δ ) (cid:0) n (cid:1) . Assumethat P is a Gallai -template of G with | Ga( P, G ) | > (1 − δ ) ( n ) . Then there exist two colors i , j ∈ [4] such that the number of edges of K n with palette { i, j } is at least (1 − · δ ) (cid:0) n (cid:1) .Proof of Theorem 6.1 for r = 4 . Let C be the collection of containers given by Theorem 2.4 for r = 4. Note that every Gallai 4-coloring of G is a subtemplate of some P ∈ C . Let δ = log − n .We define C = n P ∈ C : | Ga( P, G ) | ≤ (1 − δ ) ( n ) o , C = n P ∈ C : | Ga( P, G ) | > (1 − δ ) ( n ) o . | Ga( C , G ) | = | Ga( C , G ) | + | Ga( C , G ) | ≤ − n 24 log11 n n ) + 6 (cid:16) e ( G ) + 2 − n n n ) (cid:17) ≤ · e ( G ) + 2 − n n n ) < ⌊ n / ⌋ . A book of size q consists of q triangles sharing a common edge, which is known as the base of thebook. We write bk( G ) for the size of the largest book in a graph G and call it the booksize of G . Lemma 6.8. Let n, r ∈ Z + with r ≥ , < α, β ≪ , and G be a graph of order n . Assume thatthere exists a partition V ( G ) = A ∪ B satisfying the following conditions: (i) δ ( G [ A, B ]) ≥ ( − α ) n ; (ii) ∆( G [ A ]) , ∆( G [ B ]) ≤ βn .Then the number of Gallai r -colorings of G is at most r ⌊ n / ⌋ . Furthermore, if e ( G ) = ⌊ n / ⌋ , thenthe number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ .Proof. By Condition (i), we have ( − α ) n ≤ | A | , | B | ≤ ( + α ) n . Let e ( G ) = ⌊ n / ⌋ + m . Withoutloss of generality, we can assume that m > e ( G [ A ]) ≥ m . Then there exists a matching M in G [ A ] of size at least e ( G [ A ])2∆( G [ A ]) − ≥ m βn .For two vertices u, v ∈ A , the number of their common neighbors in B is at least | B | − | B | − δ ( G [ A, B ])) = 2 δ ( G [ A, B ]) − | B | ≥ (cid:18) − α (cid:19) n − (cid:18) 12 + α (cid:19) n ≥ n . Then, for every e ∈ G [ A ], there exists a book graph B e of size n/ e . Let B = { B e | e ∈ M } . Note that M is a matching, and therefore book graphs in B are edge-disjoint. Anothercrucial fact is that for every B ∈ B , the number of r -colorings of B without rainbow triangles is atmost r ( r + 2( r − n/ < r (3 r ) n/ , since once we color the base edge, each triangle must be coloredin the way that two of its edges share the same color. Hence, the number of Gallai r -colorings of G is at most (cid:16) r (3 r ) n (cid:17) | M | r e ( G ) −| M | ( · n ) = r e ( G ) − (1 − log r | M |· n ≤ r ⌊ n / ⌋ + m − (1 − log r m βn · n < r ⌊ n / ⌋ , where the last inequality is given by β ≪ Lemma 6.9. Let n, r ∈ Z + with r ≥ , < α ′ , β ≪ , < α, γ, ξ ≪ ε ≪ , and G be a graphof order n with e ( G ) ≤ ⌊ n / ⌋ + ξn . Assume that there exists a partition V ( G ) = A ∪ B ∪ C satisfying the following conditions: (i) d G [ A,B ] ( v ) ≥ (cid:0) − α (cid:1) n for all but at most γn vertices in A ∪ B ; (ii) δ ( G [ A, B ]) ≥ (cid:0) − α ′ (cid:1) n ; (iii) ∆( G [ A ]) , ∆( G [ B ]) ≤ βn ; (iv) 0 < | C | ≤ γn ; (v) for every v ∈ C , both d ( v, A ) , d ( v, B ) ≥ rεn .Then the number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ . roof. By Condition (i), we have (cid:18) − α (cid:19) n ≤ | A | , | B | ≤ (cid:18) 12 + α (cid:19) n. (9)For a vertex v , a set S , a set of colors R and a coloring of G , let N ( v, S ; R ) be the set of vertices u ∈ N ( v, S ), such that uv is colored by some color in R . Let d ( v, S ; R ) = | N ( v, S ; R ) | . Denoteby C the set of Gallai r -colorings of G , in which there exist a vertex v ∈ C , and two disjoint setsof colors R and R , such that both d ( v, A ; R ), d ( v, B ; R ) ≥ εn . Let C be the set of Gallai r -colorings of G , which are not in C .We first show that C = o ( r ⌊ n / ⌋ ). We shall count the ways to color G so that the resultingcolorings are in C . First, we color the edges in G [ C, A ∪ B ]; the number of ways is at most r e ( G [ C,A ∪ B ]) . Once we fix the colors of edges in G [ C, A ∪ B ], by the definition of C , there exist avertex v ∈ C , and two disjoint sets of colors R and R , such that d ( v, A ; R ), d ( v, B ; R ) ≥ εn .We observe that for every edge e = uw between N = N ( v, A ; R ) and N = N ( v, B ; R ), e eithershares the same color with uv , or with vw , as otherwise we would obtain a rainbow triangle uvw .Then the number of ways to color edges in G [ N , N ] is at most 2 e ( G [ N ,N ]) ≤ r e ( G [ N ,N ]) . Notethat by Condition (i), inequality (9) and α, γ ≪ ε , we have e ( G [ N , N ]) ≥ ( | N | − γn )( | N | − αn ) ≥ ε n . Hence, we obtainlog r |C | ≤ e ( G [ C, A ∪ B ]) + 12 e ( G [ N , N ]) + ( e ( G ) − e ( G [ C, A ∪ B ]) − e ( G [ N , N ]))= e ( G ) − e ( G [ N , N ]) ≤ ⌊ n / ⌋ + ξn − ε n , which indicates |C | = o ( r ⌊ n / ⌋ ) as ξ ≪ ε .It remains to estimate the size of C . Recall that for a coloring in C , for every vertex v ∈ C ,there are no two disjoint sets of colors R and R such that d ( v, A ; R ), d ( v, B ; R ) ≥ εn . Claim 4. Let S be a set of r colors. For every coloring in C , and every vertex v ∈ C , there existsa color R ∈ S , such that both d ( v, A ; S \ { R } ) < εn and d ( v, B ; S \ { R } ) < εn .Proof. We arbitrarily fix a coloring in C and a vertex v ∈ C . By Condition (v), there exists a color R such that d ( v, A ; R ) ≥ εn . By the definition of C , we obtain that d ( v, B ; S \ { R } ) < εn . Thenwe also have d ( v, B ; R ) ≥ d ( v, B ) − d ( v, B ; S \ { R } ) ≥ rεn − εn > εn . For the same reason, weobtain that d ( v, A ; S \ { R } ) < εn .By Claim 4, the number of ways to color edges in G [ C, A ∪ B ] is at most r X i ≤ εn (cid:18) ni (cid:19) X i ≤ εn (cid:18) ni (cid:19) r εn | C | ≤ (cid:18) r (cid:16) neǫn (cid:17) εn r εn (cid:19) | C | ≤ r ((log r e − log r ε +1)2 εn +2) | C | < r | C | n , where the last inequality is given by (log r e − log r ε + 1) 2 ε ≪ as ε ≪ 1. Note that by Condi-tions (ii)–(iv), we have • δ ( G [ A, B ]) ≥ (cid:0) − α ′ (cid:1) n ≥ (cid:0) − α ′ (cid:1) ( | A | + | B | ); • ∆( G [ A ]) , ∆( G [ B ]) ≤ βn ≤ β − γ ( | A | + | B | ).19pplying Lemma 6.8 on G [ A ∪ B ], we obtain that the number of ways to color edges in G [ A ∪ B ]is at most r ( n −| C | )24 . A trivial upper bound for the ways to color the rest of the edges, that is, theedges in G [ C ] is r ( | C | ). Hence, we havelog r |C | ≤ | C | n n − | C | ) (cid:18) | C | (cid:19) = n − (cid:18) n − | C | + 12 (cid:19) | C | ≤ ⌊ n / ⌋ − , where the last inequality is given by 0 < | C | ≤ γn and γ ≪ 1. Finally, we obtain that the numberof Gallai r -colorings of G is |C | + |C | ≤ o ( r ⌊ n / ⌋ ) + r ⌊ n / ⌋− < r ⌊ n / ⌋ . Lemma 6.10. Let n, r ∈ Z + with r ≥ , α, β, γ, ξ ≪ , and G be a graph of order n with ⌊ n / ⌋ < e ( G ) ≤ ⌊ n / ⌋ + ξn . Assume, that there exists a partition V ( G ) = A ∪ B ∪ C satisfyingthe following conditions: (i) δ ( G [ A, B ]) ≥ ( − α ) n ; (ii) ∆( G [ A ]) , ∆( G [ B ]) ≤ βn ; (iii) 0 < | C | ≤ γn ; (iv) for every v ∈ C , d ( v ) ≥ n/ .Then the number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ .Proof. Let α, γ, ξ ≪ ε ≪ 1. Let C = { v ∈ C | d ( v, A ) < rεn } , and C = { v ∈ C | d ( v, B ) < rεn } .By Conditions (iii) and (iv), for every v ∈ C , we have d ( v, B ) ≥ (cid:0) − γ − rε (cid:1) n . Similarly, forevery v ∈ C , we have d ( v, A ) ≥ (cid:0) − γ − rε (cid:1) n . Define A ′ = A ∪ C , B ′ = B ∪ C , C ′ = C \ ( C ∪ C ) . If C ′ = ∅ , then we obtain a new partition V ( G ) = A ′ ∪ B ′ satisfying the following properties: • δ ( G [ A ′ , B ′ ]) ≥ min { (cid:0) − α (cid:1) n, (cid:0) − γ − rε (cid:1) n } = (cid:0) − γ − rε (cid:1) n ; • ∆( G [ A ′ ]), ∆( G [ B ′ ]) ≤ min { ( β + γ ) n, ( rε + γ ) n } .Together with e ( G ) > ⌊ n / ⌋ , by Lemma 6.8, we obtain that the number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ . Otherwise, we obtain a new partition V ( G ) = A ′ ∪ B ′ ∪ C ′ satisfyingthe following properties: • d G [ A ′ ,B ′ ] ( v ) ≥ (cid:0) − α (cid:1) n for all but at most γn vertices in A ′ ∪ B ′ ; • δ ( G [ A ′ , B ′ ]) ≥ (cid:0) − γ − rε (cid:1) n ; • ∆( G [ A ′ ]), ∆( G [ B ′ ]) ≤ min { ( β + γ ) n, ( rε + γ ) n } ; • < | C ′ | ≤ | C | ≤ γn ; • for every v ∈ C ′ , both d ( v, A ′ ), d ( v, B ′ ) ≥ rεn .Together with e ( G ) ≤ ⌊ n / ⌋ + ξn , by Lemma 6.9, the number of Gallai r -colorings of G is strictlyless than r ⌊ n / ⌋ .Now, we prove a lemma which is crucial to the proof of Theorem 6.2.20 emma 6.11. Let n, r ∈ Z + with r ≥ , α, β, γ, ξ ≪ , and G be a graph of order n with ⌊ n / ⌋ < e ( G ) ≤ ⌊ n / ⌋ + ξn . Assume that there exists a partition V ( G ) = A ∪ B ∪ C satisfyingthe following conditions: (i) δ ( G [ A, B ]) ≥ ( − α ) n ; (ii) ∆( G [ A ]) , ∆( G [ B ]) ≤ βn ; (iii) | C | ≤ γn .Then the number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ .Proof. By Lemma 6.8, we can assume that | C | > G , greedily remove a vertex in C with degree strictly less than | G | / G to obtain a smallersubgraph. Let G ′ be the resulting graph when the algorithm terminates, and n ′ = | V ( G ′ ) | . Weremark that G ′ is not unique and it depends on the order of removing vertices. Without loss ofgenerality, we can assume that n ′ < n , as otherwise we are done by applying Lemma 6.10 on G .Let A ′ = A , B ′ = B , and C ′ = V ( G ′ ) ∩ C . Clearly, we have G ′ = G [ A ′ ∪ B ′ ∪ C ′ ]. Furthermore,by the mechanics of the algorithm, we have e ( G ) ≤ e ( G ′ ) + 12 (cid:18)(cid:18) n (cid:19) − (cid:18) n ′ (cid:19)(cid:19) . (10)We first claim that e ( G ′ ) > ⌊ ( n ′ ) / ⌋ , as otherwise we would have e ( G ) ≤ ⌊ ( n ′ ) / ⌋ + 12 (cid:18)(cid:18) n (cid:19) − (cid:18) n ′ (cid:19)(cid:19) ≤ ⌊ n / ⌋ , which contradicts the assumption of the lemma. On the other hand, since n ′ ≥ (1 − γ ) n , we obtainthat e ( G ) ≤ ⌊ n / ⌋ + ξn ≤ ⌊ ( n ′ ) / ⌋ + γ + 2 ξ − γ ) ( n ′ ) . Let ξ ′ = γ +2 ξ − γ ) . Then we have ⌊ ( n ′ ) / ⌋ < e ( G ′ ) ≤ ⌊ ( n ′ ) / ⌋ + ξ ′ ( n ′ ) . (11)If C ′ = ∅ , we obtain a vertex partition V ( G ′ ) = A ′ ∪ B ′ satisfying: • δ ( G ′ [ A ′ , B ′ ]) ≥ ( − α ) n ≥ ( − α ) n ′ ; • ∆( G ′ [ A ]), ∆( G ′ [ B ]) ≤ βn ≤ β − γ n ′ .Together with (11), by Lemma 6.8, we obtain that the number of Gallai r -colorings of G ′ , denotedby |C ( G ′ ) | , is strictly less than r ⌊ n / ⌋ . Otherwise, we find the partition V ( G ′ ) = A ′ ∪ B ′ ∪ C ′ satisfying: • δ ( G ′ [ A ′ , B ′ ]) ≥ ( − α ) n ≥ ( − α ) n ′ ; • ∆( G ′ [ A ]), ∆( G ′ [ B ]) ≤ β − γ n ′ ; • < | C ′ | ≤ γn ≤ γ − γ n ′ ; • for every v ∈ C ′ , d ( v ) ≥ n ′ . 21ogether with (11), by Lemma 6.10, we obtain that |C ( G ′ ) | < r ⌊ ( n ′ ) / ⌋ . Combining with (10), weconclude that the number of Gallai r -colorings of G , denoted by |C ( G ) | , satisfieslog r |C ( G ) | ≤ log r |C ( G ′ ) | + ( e ( G ) − e ( G ′ )) < ⌊ ( n ′ ) / ⌋ + 12 (cid:18)(cid:18) n (cid:19) − (cid:18) n ′ (cid:19)(cid:19) ≤ ⌊ n / ⌋ , which completes the proof.Another important tool we need is the stability property of book graphs proved by Bollob´asand Nikiforov [ ]. Theorem 6.12. [ ] For every < α < − and every graph G of order n with e ( G ) ≥ ( − α ) n ,either bk( G ) > (cid:18) − α / (cid:19) n or G contains an induced bipartite graph G of order at least (1 − α / ) n and with minimum degree δ ( G ) ≥ (cid:18) − α / (cid:19) n. Proof of Theorem 6.2: Let e ( G ) = ⌊ n / ⌋ + m , where 0 < m ≤ ξn . We construct a family B of book graphs by the following algorithm. We start the algorithm with B = ∅ and G = G . Inthe i-th iteration step, if there exists a book graph B of size n in G i , we let B = B ∪ { B } , and G i = G i − − e , where e is the base edge of B . The algorithm terminates when there is no bookgraph of size n/ 7. Let E be the set of base edges of B , and τ = 7 / (1 − log r |B| ≥ τ m . Since | E | = |B| ≥ τ m , the edge set E contains a matching M ofsize | E | n − − > τ m/n . Let B ′ be the set of book graphs in B whose base edges are in M . Since M is a matching, book graphs in B ′ are edge-disjoint. Note that for every B ∈ B , the numberof r -colorings of B without rainbow triangles is at most r ( r + 2( r − n/ < r (3 r ) n/ . Then thenumber of Gallai colorings of G is at most (cid:16) r (3 r ) n (cid:17) | M | r e ( G ) −| M | (1+2 · n ) = r ⌊ n / ⌋ + m − (1 − log r | M | n < r ⌊ n / ⌋ + m − m = r ⌊ n / ⌋ . It remains to consider the case for |B| < τ m . Without loss of generality, we can assume thatthere is no matching of size greater than τ m/n in E . Let G ′ = G − E . Then we have e ( G ′ ) > ⌊ n / ⌋ − (2 τ − m. Furthermore, by the construction of G ′ , we obtain that bk( G ′ ) < n/ 7. Let α = (2 τ − ξ. Byapplying Theorem 6.12 on G ′ , we obtain that there is a vertex partition V ( G ′ ) = A ′ ∪ B ′ ∪ C ′ with | C ′ | ≤ α / n , such that A ′ , B ′ are independent sets, and δ ( G ′ [ A ′ , B ′ ]) ≥ (cid:18) − α / (cid:19) n. Let G be the spanning subgraph of G with edge set E . For a small constant β with ξ ≪ β ≪ V be the set of vertices in G with degree more than βn . Since | E | < τ m ≤ τ ξn , we have | V | ≤ (4 τ ξ/β ) n ≤ βn . Let A = A ′ \ V , B = B ′ \ V , and C = C ′ ∪ V . Then we obtain a vertexpartition V ( G ) = A ∪ B ∪ C satisfying the following conditions: • δ ( G [ A, B ]) ≥ ( − α / − β ) n ; • ∆( G [ A ]), ∆( G [ B ]) ≤ βn ; • | C | ≤ ( α / + β ) n. By Lemma 6.11, we obtain that the number of Gallai r -colorings of G is strictly less than r ⌊ n / ⌋ .22 .4 Proof of Theorem 6.3 We say that a graph G is t -far from being k -partite if χ ( G ′ ) > k for every subgraph G ′ ⊂ G with e ( G ′ ) > e ( G ) − t . We will use the following theorem of Balogh, Bushaw, Collares, Liu, Morris, andSharifzadeh [ ]. Theorem 6.13. [ ] For every n, k, t ∈ N , the following holds. Every graph G of order n which is t -far from being k -partite contains at least n k − e k · k ! (cid:18) e ( G ) + t − (cid:18) − k (cid:19) n (cid:19) copies of K k +1 . Proposition 6.14. Let n ∈ N and < ε ≤ . Every graph F on at least εn vertices, which containsat most n − / (cid:0) n (cid:1) triangles, satisfies e ( F ) ≤ | F | e n / ε | F | . Proof. Let t = e n / ε | F | . Assume that e ( F ) > | F | + t . Then F is t -far from being bipartite. ByTheorem 6.13, the number of triangles in F is at least | F | e (cid:18) e ( F ) + t − | F | (cid:19) > | F | e · t = 16 n / ε | F | > n − / (cid:18) n (cid:19) , which gives a contradiction.For an r -template P of order n , we say that an edge e of K n is an r -edge of P if | P ( e ) | ≥ r -edge e is typical if the number of rainbow triangles containing e is at most n / . We thenimmediately obtain the following proposition. Proposition 6.15. For an r -template of order n containing at most n − / (cid:0) n (cid:1) rainbow triangles,the number of r -edges of P , which is not typical, is at most n / . We now prove the following lemma. Lemma 6.16. Let n, r ∈ N with r ≥ , and n − / ≪ ξ ≤ log − n ≪ . Assume that G is agraph of order n with ( + 3 ξ ) n ≤ e ( G ) ≤ ( − ξ ) n , and P is a Gallai r -template of G . Then,for sufficiently large n , log r | Ga( P, G ) | ≤ n − ξ n n / . Proof. We first construct a subset I of [ n ] and a sequence of graphs { G , G , . . . , G ℓ } by the followingalgorithm. We start the algorithm with I = ∅ and G = G . In the i -th iteration step, we eitheradd a vertex v to I , whose degree is at most ( − ξ )( | G i | − 1) in the graph G i , or add a pair ofvertices { u, v } to I , where uv is a typical r -edge satisfying | N G i ( u ) ∩ N G i ( v ) | ≥ ξ ( | G i | − G i +1 = G − I . The algorithm terminates when neither of the above types ofvertices exists.Assume that the algorithm terminates after ℓ steps. Let G ′ = G ℓ and k = | G ′ | . We now makethe following claim. Claim 5. log r | Ga( P, G ) | ≤ (cid:18) − ξ (cid:19) (cid:18) n − k (cid:19) + 3 n / + log r | Ga( P, G ′ ) | . roof. In the i -th iteration step of the above algorithm, if we add to I a single vertex v , then thenumber of ways to color the incident edges of v in G i satisfieslog r Q e is incident to v in G i | P ( e ) | ≤ d G i ( v ) ≤ ( − ξ )( | G i | − . Now we assume that what we add is a pair of vertices { u, v } . For every w ∈ N G i ( u ) ∩ N G i ( v ),vertices uvw either span a rainbow triangle in P , or satisfy | P ( uw ) | = | P ( vw ) | = 1. Together withthe fact that uv is a typical r -edge, we obtain that the number of ways to color the edges, whichare incident to v or u in G i , satisfieslog r Q e is incident to u or v in G i | P ( e ) | ≤ | G i | − − | N G i ( u ) ∩ N G i ( v ) | + 2 n / + 1 ≤ (1 − ξ )( | G i | − 2) + 2 n / + 1 . From the above discussion, we conclude that the number of ways to color edges in E ( G ) − E ( G ′ )satisfies log r Q e ∈ E ( G ) − E ( G ′ ) | P ( e ) | ≤ (cid:0) − ξ (cid:1) (cid:16) n − k (cid:17) + n (1 + 2 n / ) , which implies the claim.We now split the proof into several cases. Case 1: k ≤ ξ n .Then | Ga( P, G ′ ) | ≤ r k / ≤ r ξ n / , and therefore by Claim 5 and ξ ≪ 1, we obtain thatlog r | Ga( P, G ) | ≤ (cid:18) − ξ (cid:19) n n / + ξ n / ≤ n − ξ n n / . Case 2: e ( G ′ ) > (cid:0) − ξ (cid:1) k and k > ξ n .Since 2 ξ ≤ log − n ≤ log − k , for sufficiently large n , Theorem 6.1 indicates that | Ga( P, G ′ ) | ≤ r k / . We claim that k ≤ (1 − ξ ) n , as otherwise we would have e ( G ) ≥ e ( G ′ ) > (cid:18) − ξ (cid:19) k > (cid:18) − ξ (cid:19) (1 − ξ ) n ≥ (cid:18) − ξ (cid:19) n , which is contradiction with the assumption of the lemma. Therefore, by Claim 5, we obtain thatlog r | Ga( P, G ) | ≤ (cid:0) − ξ (cid:1) (cid:16) n − k (cid:17) + 3 n / + k ≤ n − ξ n + ξ k + 3 n / ≤ n − ξ n + ξ (1 − ξ ) n + 3 n / ≤ n − ξ n + 3 n / . Case 3: e ( G ′ ) < (cid:0) + 2 ξ (cid:1) k and k > ξ n .Since 2 ξ ≪ 1, Theorem 6.2 indicates that | Ga( P, G ′ ) | ≤ r k / . We claim that k ≤ (1 − ξ ) n , asotherwise we would have e ( G ) < (cid:16) n − k (cid:17) + (cid:0) + 2 ξ (cid:1) k < n − (cid:0) − ξ (cid:1) k < n − (cid:0) − ξ (cid:1) (1 − ξ ) n ≤ n − (cid:0) − ξ (cid:1) n = (cid:0) + 3 ξ (cid:1) n , which is contradiction with the assumption of the lemma. Similarly, as in Case 2, we obtain thatlog r | Ga( P, G ) | ≤ (cid:18) − ξ (cid:19) (cid:18) n − k (cid:19) + 3 n / + k ≤ n − ξ n n / . ase 4: ( + 2 ξ ) k ≤ e ( G ′ ) ≤ ( − ξ ) k and k > ξ n .Denote by e r ( G ′ ) the number of r -edges of P in G ′ . Let A = { v ∈ V ( G ′ ) | d G ′ ( v ) ≤ (cid:0) + ξ (cid:1) k } . Claim 6. All the typical r -edges of G ′ have both endpoints in A .Proof. First, by the construction of G ′ , we have the following two properties: for every v ∈ V ( G ′ ), d G ′ ( v ) > (cid:18) − ξ (cid:19) ( k − , (12)and for every typical r -edge uv in G ′ , d G ′ ( u ) + d G ′ ( v ) ≤ k − 2) + | N G i ( u ) ∩ N G i ( v ) | < (1 + 2 ξ ) k. (13)Suppose that there exists a typical r -edge uv such that u is not in A , i.e. d G ′ ( u ) > (cid:0) + ξ (cid:1) k . Thenby (12) and ξ ≪ 1, we have d G ′ ( u ) + d G ′ ( v ) > (cid:18) 12 + ξ (cid:19) k + (cid:18) − ξ (cid:19) ( k − > (1 + 2 ξ ) k, which contradicts (13). Subcase 4.1: | A | ≤ ξk .By Proposition 6.15 and Claim 6, we have e r ( G ′ ) ≤ (cid:18) | A | (cid:19) + n / ≤ ξ k n / . Therefore, together with the assumption of Case 4, we obtain thatlog r | Ga( P, G ′ ) | ≤ log r (cid:16) r e r ( G ′ ) e ( G ′ ) − e r ( G ′ ) (cid:17) ≤ ( e ( G ′ ) + e r ( G ′ )) ≤ (cid:16)(cid:0) − ξ (cid:1) k + ξ k + n / (cid:17) = k − (cid:0) ξ − ξ (cid:1) k + n / . Then by Claim 5,log r | Ga( P, G ) | ≤ (cid:0) − ξ (cid:1) (cid:16) n − k (cid:17) + 3 n / + k − (cid:0) ξ − ξ (cid:1) k + n / ≤ n − ξ n − (cid:0) ξ − ξ (cid:1) k + 4 n / ≤ n − ξ n + 4 n / , where the last inequality is given by ξ ≪ Subcase 4.2: | A | > ξk .By the definition of A , the number of non-edges of G ′ is at least12 (cid:18) k − − (cid:18) 12 + ξ (cid:19) k (cid:19) | A | = 12 (cid:18)(cid:18) − ξ (cid:19) k − (cid:19) | A | . (14)We first claim that | A | ≤ − ξ − ξ k, (15)as otherwise we would obtain that the number of non-edges of G ′ is more than12 (cid:18) − ξ (cid:19) k · − ξ − ξ k − | A | ≥ (cid:18) − ξ (cid:19) k − k − ξ ) k − | A | ≥ ξk. (16)By Propositions 6.14 and 6.15, since | A | > ξk > ξ n , we have e r ( G ′ ) ≤ e ( G ′ [ A ]) + n / ≤ | A | e n / ξ | A | + n / , as otherwise we would find more than n − / (cid:0) n (cid:1) rainbow triangles, which contradicts the assumptionthat P is a Gallai r -template of G . Since ξ ≫ n − / , we have e r ( G ′ ) ≤ | A | ξ | A | + n / . (17)Combining (14), (16) and (17), we havelog r | Ga( P, G ′ ) | ≤ ( e ( G ′ ) + e r ( G ′ )) ≤ (cid:16)(cid:0) k (cid:1) − (cid:0)(cid:0) − ξ (cid:1) k − (cid:1) | A | + | A | + ξ | A | + n / (cid:17) ≤ k − | A | ((1 − ξ ) k − | A | ) + ξ | A | + n / ≤ k − ξ | A | k + ξ | A | + n / . Then by Claim 5 and the assumption of Subcase 4.2, we obtain thatlog r | Ga( P, G ) | ≤ (cid:0) − ξ (cid:1) (cid:16) n − k (cid:17) + 3 n / + k − ξ | A | k + ξ | A | + n / < (cid:0) − ξ (cid:1) (cid:16) n − k (cid:17) + 3 n / + k − ξ k + ξ n + n / ≤ n − ξ n + 4 n / . Proof of Theorem 6.3. Let C be the collection of containers given by Theorem 2.4. Theorem 2.4indicates that every Gallai r -coloring of G is a subtemplate of some P ∈ C and |C| ≤ cn − / log n ( n )for some constant c , which only depends on r . We may assume that all templates P in C are Gallai r -templates of G . By Property (ii) of Theorem 2.4, we always have RT( P ) ≤ n − / (cid:0) n (cid:1) . Supposethat for a template P there exists an edge e ∈ E ( G ) with | P ( e ) | = 0. Then we would obtain | Ga( P, G ) | = 0 as a Gallai r -coloring of G requires at least one color on each edge. Now applyingLemma 6.16 on every container P ∈ C , we obtain that the number of Gallai r -colorings of G is atmost X P ∈C | Ga( P, G ) | ≤ |C| · r n − ξ n +4 n / < r ⌊ n / ⌋ , where the last inequality follows from ξ ≫ n − / for n sufficiently large. References [1] N. Alon, J. Balogh, P. Keevash, and B. Sudakov , The number of edge colorings with nomonochromatic cliques , Journal of the London Mathematical Society, 70 (2004), pp. 273–288.[2] J. Balogh, B. Bollob´as, and M. Simonovits , The number of graphs without forbiddensubgraphs , Journal of Combinatorial Theory, Series B, 91 (2004), pp. 1–24.[3] J. Balogh, N. Bushaw, M. Collares, H. Liu, R. Morris, and M. Sharifzadeh , Thetypical structure of graphs with no large cliques , Combinatorica, 37 (2017), pp. 617–632.264] J. Balogh, R. Morris, and W. Samotij , Independent sets in hypergraphs , Journal of theAmerican Mathematical Society, 28 (2015), pp. 669–709.[5] , The method of hypergraph containers , arXiv:1801.04584, (2018).[6] J. Balogh and J. Solymosi , On the number of points in general position in the plane ,arXiv:1704.05089, (2017).[7] J. Balogh and A. Z. Wagner , Further applications of the container method , in RecentTrends in Combinatorics, Springer, 2016, pp. 191–213.[8] J. O. Bastos, F. S. Benevides, G. O. Mota, and I. Sau , Counting Gallai 3-colorings ofcomplete graphs , arXiv:1805.06805, (2018).[9] F. S. Benevides, C. Hoppen, and R. M. Sampaio , Edge-colorings of graphs avoidingcomplete graphs with a prescribed coloring , Discrete Mathematics, 340 (2017), pp. 2143–2160.[10] B. Bollob´as and V. Nikiforov , Books in graphs , European Journal of Combinatorics, 26(2005), pp. 259–270.[11] K. Cameron, J. Edmonds, and L. Lov´asz , A note on perfect graphs , Periodica Mathe-matica Hungarica, 17 (1986), pp. 173–175.[12] P. Erd˝os , Some new applications of probability methods to combinatorial analysis and graphtheory , University of Calgary, Department of Mathematics, Statistics and Computing Science,1974.[13] V. Falgas-Ravry, K. O’Connell, and A. Uzzell , Multicolour containers, extremal en-tropy and counting , Random Structures & Algorithms, (2018).[14] J. Fox, A. Grinshpun, and J. Pach , The Erd˝os–Hajnal conjecture for rainbow triangles ,Journal of Combinatorial Theory, Series B, 111 (2015), pp. 75–125.[15] T. Gallai , Transitiv orientierbare graphen , Acta Mathematica Hungarica, 18 (1967), pp. 25–66.[16] A. Gy´arf´as and G. N. S´ark¨ozy , Gallai colorings of non-complete graphs , Discrete Math-ematics, 310 (2010), pp. 977–980.[17] A. Gy´arf´as, G. N. S´ark¨ozy, A. Seb˝o, and S. Selkow , Ramsey-type results for Gallaicolorings , Journal of Graph Theory, 64 (2010), pp. 233–243.[18] A. Gy´arf´as and G. Simonyi , Edge colorings of complete graphs without tricolored triangles ,Journal of Graph Theory, 46 (2004), pp. 211–216.[19] C. Hoppen, H. Lefmann, and K. Odermann , A rainbow Erd˝os-Rothschild problem , Elec-tronic Notes in Discrete Mathematics, 49 (2015), pp. 473–480.[20] , On graphs with a large number of edge-colorings avoiding a rainbow triangle , EuropeanJournal of Combinatorics, 66 (2017), pp. 168–190.[21] , A rainbow Erd˝os-Rothschild problem , SIAM Journal on Discrete Mathematics, 31 (2017),pp. 2647–2674. 2722] J. K¨orner and G. Simonyi , Graph pairs and their entropies: modularity problems , Combi-natorica, 20 (2000), pp. 227–240.[23] L. Lov´asz , Combinatorial problems and exercises , North-Holland Publishing Co., Amsterdam,1979.[24] D. Saxton and A. Thomason , Hypergraph containers , Inventiones mathematicae, 201(2015), pp. 925–992.[25]