1 Introduction

Mantel’s Theorem from 1907 [21] is one of the foundational results in extremal graph theory. It asserts that a triangle-free graph G on n vertices has at most \(\lfloor \frac{n^2}{4}\rfloor \) edges, with equality if and only if G is (isomorphic to) the complete balanced bipartite graph \(T_2(n)\). While the proof of Mantel’s theorem is a simple combinatorial exercise, triangle-free graphs act as a kind of theoretical lodestone in extremal combinatorics: many important extremal tools or problems are first developed or studied in the context of triangle-free graphs. One may think, for example, of results on the independence number of triangle-free graphs [23], the chromatic threshold phenomenon [2, 24], the triangle removal lemma [22], and on random [8] and tripartite [6] versions of Mantel’s theorem.

In this paper we will consider a rainbow variation on Mantel’s triangle-free theme, which was first introduced by Gallai in 1967. Fix an n-set V and some integer \(r \ge 2\).

Definition 1.1

(Colouring templates, colourings) An r-colouring template on V is an r-tuple \(\textbf{G}^{(r)}=(G_1, G_2, \ldots , G_r)\), where each of the \(G_i\) is a graph on V. Whenever r is clear from context, we omit the superscript r and write \(\textbf{G}\) for \(\textbf{G}^{(r)}\).

An r-coloured graph (Hc) is a graph \(H=(V(H), E(H))\) together with an r-colouring of its edges \(c: \ E(H)\rightarrow \{1,2, \ldots , r\}\). (Note that an r-coloured graph may be identified with an r-colouring template where the colour classes \(G_i\), \(1\le i\le r\), are pairwise edge-disjoint.)

Definition 1.2

(Coloured and rainbow subgraphs) Given an r-coloured graph (Hc), we say that an r-colouring template \(\textbf{G}^{(r)}\) on a vertex set V contains a copy of (Hc) as a subgraph if there is an injection \(f: \ V(H)\rightarrow V\) such that for each edge \(e=\{x,y\} \in E(H)\) we have \(\{f(x),f(y)\}\in G_{c(e)}\). Further, given a graph H, we say that \(\textbf{G}\) contains a rainbow copy of H if \(\textbf{G}\) contains (Hc) for some r-colouring \(c: \ E(H)\rightarrow \{1,2, \ldots , r\}\) assigning distinct colours to distinct edges.

Gallai [16] initiated the study of r-colourings with no rainbow triangles, proving a structure theorem that was subsequently re-discovered and extended by a number of other researchers [7, 17]; in honour of his pioneering contributions to the area, r-coloured graphs containing no rainbow triangle are known as Gallai colourings. We accordingly refer to r-colouring templates not containing a rainbow copy of \(K_3\) as Gallai colouring templates.

Gallai colourings have been extensively studied. For instance, there are connections between Gallai colourings and information theory [19], and a considerable interest in counting the number of Gallai colourings and characterising their typical structure [4, 5, 12]. A large body of work has been dedicated to research on Gallai colourings from a Ramsey-theoretic perspective, giving rise to ‘Gallai–Ramsey theory’—see the dynamic survey [15] devoted to the area.

In this paper, we focus instead on Turán-style questions for Gallai colouring templates. One of the first results of this kind was obtained by Keevash, Saks, Sudakov and Verstraëte [18], who determined the arithmetic mean of the size of the colour classes \(G_1, G_2, \ldots G_r\) required to guarantee the existence of a rainbow \(K_3\) in an r-colouring template. As a special case of more general results on rainbow cliques, they proved the following [18, Theorem 1.2]:

Theorem 1.3

(Keevash, Saks, Sudakov, Verstraëte) If \(\textbf{G}\) is a Gallai r-colouring template on n vertices for n sufficiently large, then

$$\begin{aligned} \frac{1}{r}\sum _{i=1}^r \vert E(G_i)\vert \le \left\{ \begin{array}{ll} \frac{2}{3}\left( {\begin{array}{c}n\\ 2\end{array}}\right) &{}\text { if }r=3,\\ \left\lfloor \frac{n^2}{4}\right\rfloor &{} \text { if }r\ge 4, \end{array} \right. \end{aligned}$$

and these upper bounds are best possible.

The lower bound constructions in Theorem 1.3 are the trivial ones: for \(r\ge 4\), one takes \(G_1=G_2=\ldots =G_r=T_2(n)\), while for \(r=3\) one takes \(G_1=G_2=K_n\) and lets \(G_3\) be the empty graph. Given that this latter construction features an empty colour class, it is natural to ask how the bound in Theorem 1.3 changes in the \(r=3\) case if one requires all three of the colour classes \(G_1\), \(G_2\) and \(G_3\) to be large. This question was first posed by Diwan and Mubayi in a 2006 manuscript [9]: what is the least \(\alpha >0\) such that for all n sufficiently large, every 3-colouring template \(\textbf{G}\) on an n-set V with \(\min \{\vert E(G_i)\vert : \ 1\le i\le 3\}>\alpha n^2\) contains a rainbow triangle? In other words, how large do you need the smallest of the three colour classes to be in order to guarantee the existence of a rainbow triangle?

Magnant [20, Theorem 5] answered this question in 2015 under the assumption that the union of the colour classes \(G_i\), \(1\le i\le 3\), covers all pairs in V. This assumption may seem natural, insofar as one seeks to make all colour classes large, but it also introduces some very strong restrictions on the colouring template \(\textbf{G}\). Indeed, if \(\{x,y\}\in E(G_i)\cap E(G_j)\) and \(\{x,z\}\in E(G_i)\cap E(G_k)\) for some distinct indices \(1\le i,j,k \le 3\), then if the edge \(\{y,z\}\) belongs to any of the three colour classes we have a rainbow triangle. Thus Magnant’s assumption rules out any vertex being adjacent to two ‘bi-chromatic edges’ with distinct colour pairs. In a 2020 paper, Aharoni, DeVos, de la Maza, Montejanos and Šámal [1, Theorem 1.2] did away with Magnant’s technical assumption and answered the question of Diwan and Mubayi in full. Let \(\tau :=\frac{4-\sqrt{7}}{9}\).

Theorem 1.4

(Aharoni, DeVos, de la Maza, Montejano and Šámal) For all n sufficiently large, any n-vertex 3-colouring template \(\textbf{G}\) satisfying

$$\begin{aligned}\min \left\{ \vert E(G_1)\vert , \vert E(G_2)\vert , \vert E(G_3)\vert \right\} >\frac{1+\tau ^2}{4}n^2\end{aligned}$$

contains a rainbow triangle.

Moreover, the lower bound in Theorem 1.4 is tight up to a O(n) additive term, as can be seen by considering the following family of constructions. Set \(\left[ n\right] :=\{1,2\ldots , n\}\), and write \(S^{\left( 2\right) }\) for the collection of unordered pairs of elements from a set S.

Construction 1.5

(\(\textbf{F}(a,b,c)\)-templates) Let a, b and c be non-negative integers with \(a+b+c=n\). Arbitrarily partition \(\left[ n\right] \) as \(\left[ n\right] =A\sqcup B\sqcup C\), with \(\left| A\right| =a\), \(\left| B\right| =b\) and \(\left| C\right| =c\). Define graphs \(F_1\), \(F_2\) and \(F_3\) on the vertex set \(\left[ n\right] \) by setting

$$\begin{aligned} F_{1}:=A^{\left( 2\right) }\cup B^{\left( 2\right) },{} & {} F_{2}:=A^{\left( 2\right) }\cup C^{\left( 2\right) }, \text { and }{} & {} F_{3}:=\left[ n\right] ^{(2)}\setminus A^{\left( 2\right) }.\end{aligned}$$

Write \(\textbf{F}=\textbf{F}(a,b,c)\) for (any instance of) the n-vertex 3-colouring template \((F_1, F_2, F_3)\).

See Fig. 1 for a picture of the 3-colouring template \(\textbf{F}(a,b,c)\). It is readily checked that \(\textbf{F}\) is rainbow \(K_3\)-free, and that setting \(b=c=\lceil \tau n\rceil \) and \(a=n-2\lceil \tau n\rceil \) we have that all three colour classes \(F_1\), \(F_2\) and \(F_3\) contain \(\frac{1+\tau ^2}{4}n^2 +O(n)\) edges.

The authors of [1] suggested the more general problem of determining which triples of edge densities \((\alpha _1, \alpha _2, \alpha _3)\) force a rainbow triangle [1, Problem 1.3].

Definition 1.6

(Forcing triple) A triple \((\alpha _1, \alpha _2, \alpha _3)\in [0,1]^3\) is a forcing triple if for all n sufficiently large, every n-vertex 3-colouring template \(\textbf{G}\) satisfying \(e(G_i)>\min \left( \frac{\alpha _i}{2} n^2, \left( {\begin{array}{c}n\\ 2\end{array}}\right) -1\right) \) for \(i\in \{1,2,3\}\) must contain a rainbow triangle.

In this terminology,Footnote 1 the authors of [1] proposed the following generalisation of Diwan and Mubayi’s question:

Problem 1.7

Determine the set of forcing triples.

Fig. 1
figure 1

The Gallai colouring templates \(\textbf{F}\left( a,b,c\right) \) and \(\textbf{H}\left( a,b,c\right) \) with red (thin lines), green (thick lines) and blue (doubled lines) representing edges in colours 1, 2 and 3 respectively. (Colur figure online)

Recently Frankl [13, Theorem 1.4] gave a new proof of Theorem 1.3 on the maximum arithmetic mean of the sizes of the colour classes in a Gallai r-colouring template, and raised the problem of maximising the geometric mean of the sizes of the colour classes for such templates in the caseFootnote 2\(r=3\). This can be viewed as a different way of forcing all three colour classes \(G_1\), \(G_2\) and \(G_3\) to be (reasonably) large, and of moving away from the extremal construction where two of the colour classes are complete and the third is empty.

Frankl proved an upper bound of \(\left\lfloor \frac{n^2}{4}\right\rfloor \) on this geometric mean under the assumption that the colour classes were nested [13, Theorem 1.5]. This result is tight under the nestedness assumption: a lower bound construction is obtained by taking three identical copies of \(T_2(n)\) for the three colour classes.

Frankl conjectured that his upper bound on the geometric mean was tight in general, without the nestedness assumption on the colour classes [13, Conjecture 3]. This was subsequently disproved by Frankl, Győri, He, Lv, Salia, Tompkins, Varga and Zhu, who provided a different construction, which they conjectured [14, Conjecture 2] maximises the geometric mean of the sizes of the colour classes in a Gallai 3-colouring template. Their construction turns out to be a special case of a more general construction that will play a key role in this paper, and which we define below. Write \((S, T)^{(2)}\) for the collection of unordered pairs taking one vertex from each of S and T.

Construction 1.8

(\(\textbf{H}(a,b,c)\)-templates) Let a, b and c be non-negative integers with \(a+b+c=n\). Arbitrarily partition \(\left[ n\right] \) as \(\left[ n\right] =A\sqcup B\sqcup C\), with \(\left| A\right| =a\), \(\left| B\right| =b\) and \(\left| C\right| =c\). Define graphs \(H_1\), \(H_2\) and \(H_3\) on the vertex set \(\left[ n\right] \) by setting

$$\begin{aligned}&H_{1}:=A^{\left( 2\right) }\cup \left( B\cup C\right) ^{\left( 2\right) }\cup \left( A,C\right) ^{\left( 2\right) },\quad H_{2}:=A^{\left( 2\right) }, \text { and }\\ {}&H_{3}:=\left( B\cup C\right) ^{\left( 2\right) }\cup \left( A,B\right) ^{\left( 2\right) }. \end{aligned}$$

Write \(\textbf{H}=\textbf{H}(a,b,c)\) for (any instance of) the n-vertex 3-colouring template \((H_1, H_2, H_3)\).

See Fig. 1 for a picture of the 3-colouring template \(\textbf{H}(a,b,c)\). The special case \(c=0\), \(b=n-a\) corresponds to the constuction provided by the authors of [14]. It is readily checked that \(\textbf{H}\) is rainbow \(K_3\)-free. Let \(\upsilon \) denote the value of \(x\in [0,1]\) maximising the value of the function

$$\begin{aligned}h: \ x\mapsto \left( x^2+(1-x)^2\right) x^2\left( 1-x^2\right) .\end{aligned}$$

The value of \(\upsilon \) may be computed explicitly, though the exact form is not pleasant. Numerically, we have \(\upsilon \approx 0.7927\) and \(h(\upsilon )\approx 0.1568\). Setting \(a=\lceil \upsilon n\rceil \), \(b=n-a\) and \(c=0\), we have that

$$\begin{aligned} \Bigl (\vert E(H_1)\vert \cdot \vert E(H_2)\vert \cdot \vert E(H_3)\vert \Bigr )^{\frac{1}{3}}=\left( h(\upsilon )+o(1)\right) ^{\frac{1}{3}} \frac{n^2}{2}= \left( 0.5392+o(1)\right) \frac{n^2}{2}, \end{aligned}$$

which is significantly larger than \(\left\lfloor \frac{n^2}{4}\right\rfloor \) for all n sufficiently large. Thus, as noted by the authors of [14], the Gallai 3-colouring template \(\textbf{H}\) for these values of a, b and c provides a counterexample to the aforementioned conjecture of Frankl. However they conjectured [14, Conjecture 2] that asymptotically one could not do better than the \(\textbf{H}(\lceil \upsilon n\rceil , n-\lceil \upsilon n \rceil , 0)\) Gallai 3-colouring template:

Conjecture 1.9

(Frankl, Győri, He, Lv, Salia, Tompkins, Varga and Zhu) Let \(\textbf{G}\) be a Gallai 3-colouring template on n vertices. Then

$$\begin{aligned} \Bigl ( \vert E(G_1)\vert \cdot \vert E(G_2)\vert \cdot \vert E(G_3)\vert \Bigr )^{\frac{1}{3}} \le \left( h(\upsilon )+o(1)\right) ^{\frac{1}{3}} \left( {\begin{array}{c}n\\ 2\end{array}}\right) . \end{aligned}$$

The authors of [14] proved their conjecture under the assumption that the union of the colour classes covers the entire graph [14, Theorem 2]—the same assumption made earlier by Magnant, and which, as we remarked above, is both natural and highly restrictive in terms of the possible structure of \(\textbf{G}\).

1.1 Results

In the present work we fully resolve Problem 1.7. This asymptotically generalises previous Turán-type results for Gallai 3-colouring templates (Theorem 1.3 and Theorem 1.4), and settles Conjecture 1.9 in the affirmative. To state our result, we must define three regions in \([0,1]^2\).

Definition 1.10

Let \(\mathcal {R}_1\) denote the collection of \((\alpha _1, \alpha _2)\in [0,1]^2\) satisfying:

$$\begin{aligned} \max \left( 1-\alpha _2, \frac{1+\tau ^2}{2}, \alpha _2 \right) \le \alpha _1 \le 1-2\sqrt{\alpha _2}+2\alpha _2. \end{aligned}$$

For \((\alpha _1, \alpha _2)\in \mathcal {R}_1\) there existsFootnote 3 a unique pair (xy) of non-negative real numbers such that \(x\ge \frac{1}{2}\), \(x+y\le 1\) and \(\alpha _1=x^2+y^2\), \(\alpha _2=x^2+(1-x-y)^2\); we refer to this pair as the canonical representation of \((\alpha _1, \alpha _2)\in \mathcal {R}_1\). We define \(\mathcal {R}'_1\) to be the collection of \((\alpha _1, \alpha _2)\in \mathcal {R}_1\) whose canonical representation (xy) satisfies \(2x^2+(1-x-y)^2\ge 1\).

Remark 1.11

We can in principle compute the canonical pair (xy) explicitly from \((\alpha _1, \alpha _2)\): setting \(y=\sqrt{\alpha _1-x^2}\), we need x to be a solution in \([\frac{1}{2},\sqrt{\alpha _1}]\) to the equation

$$\begin{aligned} \alpha _1-\alpha _2 = (1-x)\left( x+2 \sqrt{\alpha _1 -x^2} - 1\right) \end{aligned}$$
(1.1)

while satisfying \(x+\sqrt{\alpha _1-x^2}\le 1\). Now, (1.1) can be rewritten as a quartic equation

$$\begin{aligned} \left( \alpha _1-\alpha _2+(1-x)^2\right) ^2 =4(1-x)^2(\alpha _1-x^2), \end{aligned}$$

whose solutions can be computed explicitly via radicals in terms of \(\alpha _1\) and \(\alpha _2\). Further, as we show in Proposition 2.3, for \((\alpha _1, \alpha _2)\in \mathcal {R}_1\), there exists a unique such solution \(x_{\star }=x_{\star }(\alpha _1, \alpha _2)\) in the interval \([\frac{1}{2},1]\), and that setting \(y_{\star }=\sqrt{\alpha _1 -(x_{\star }) ^2 }\) we have \(x_{\star }\le \sqrt{\alpha _1}\) and \(x_{\star }+y_{\star }\le 1\), yielding the canonical pair \((x_{\star }, y_{\star })\). The boundary between \(\mathcal {R}'_1\) and \(\mathcal {R}_1\setminus \mathcal {R}'_1\) then corresponds to the solutions \((\alpha _1, \alpha _2)\in \mathcal {R}_1\) to the equation

$$\begin{aligned} 2(x_{\star }(\alpha _1, \alpha _2))^2+(1-x_{\star }(\alpha _1, \alpha _2)-\sqrt{\alpha _1 -(x_{\star }(\alpha _1, \alpha _2))^2})^2=1. \end{aligned}$$

Definition 1.12

Let \(\mathcal {R}_2\) denote the collection of \((\alpha _1, \alpha _2)\in [0,1]^2\) satisfying

$$\begin{aligned} \alpha _1 \ge \max \left( 2-2\sqrt{\alpha _2}, 1-2\sqrt{\alpha _2}+2\alpha _2\right) . \end{aligned}$$

Note that for all pairs \((\alpha _1, \alpha _2)\in \mathcal {R}_1\cup \mathcal {R}_2\) we have \(\frac{1}{4}\le \alpha _2\le \alpha _1\) and \(\frac{1}{2}< \alpha _1\). See Fig. 2 for a picture of the regions \(\mathcal {R}'_1\) and \(\mathcal {R}_2\).

Fig. 2
figure 2

The regions \(\mathcal {R}'_1\) (upper part, in green) and \(\mathcal {R}_2\) (lower part, in blue) in the \((\alpha _1, \alpha _2)\) plane. The left-most point of \(\mathcal {R}'_1\) is \((\frac{1+\tau ^2}{2},\frac{1+\tau ^2}{2})\), the left-most point of \(\mathcal {R}_2\) is \((2-\sqrt{2},\frac{1}{2})\), and the extreme points along the vertical line \(\alpha _1=1\) are \((1, \frac{1}{4})\) and (1, 1). (Colur figure online)

Before stating our main result, we record a useful observation of Aharoni et al. [1]. Suppose that there exists an N-vertex Gallai colouring template \(\textbf{G}\) with no rainbow triangle satisfying \(e(G_i) = \frac{\alpha _i}{2} N^2 + \varepsilon _i N^2\) for each \(i\in \{1,2,3\}\), where the \(\varepsilon _i\) are strictly positive real numbers. Write \(\mathbf {G(k)}\) for the balanced blow-up of \(\textbf{G}\) obtained by replacing each vertex v of \(\textbf{G}\) by a set of k vertices \(X_v\) and for each i replacing each edge \(uv\in E(G_i)\) by a complete balanced bipartite graph between \(X_u\) and \(X_v\). Then for any \(C > 0\) and all k sufficiently large, we have

$$\begin{aligned} e(G(k)_i) =\frac{1}{2}\alpha _{i}(kN)^2 + \varepsilon _i (kN)^2 > \alpha _{i} \left( {\begin{array}{c}kN\\ 2\end{array}}\right) + CkN. \end{aligned}$$

Since \(\textbf{G}(k)\) is rainbow triangle-free, this implies the existence of Gallai colouring templates \(\textbf{J}\) on \(n>N\) vertices with \(e(J_i) > \alpha _i \left( {\begin{array}{c}n\\ 2\end{array}}\right) + Cn\) for each \(i\in \{1,2,3\}\). In particular, it is enough to resolve Problem 1.7 up to additive linear terms and with the normalisation factor \(n^2\) replaced by the more conventional factor \(\left( {\begin{array}{c}n\\ 2\end{array}}\right) \).

With this observation in place, we can now state our main result: for any pair of densities \(1\ge \alpha _1\ge \alpha _2\ge 0\), we determine the least \(\alpha _3\le \alpha _2\) such that \((\alpha _1, \alpha _2, \alpha _3)\) is a forcing triple. We note that the case \(\alpha _1=1\) is trivial: consider an n-vertex 3-colouring template \(\textbf{G}\) with \(\vert G_1\vert =\left( {\begin{array}{c}n\\ 2\end{array}}\right) \) and \(\vert G_i\vert >\alpha _i\left( {\begin{array}{c}n\\ 2\end{array}}\right) \) for \(i\in \{2,3\}\). If any vertex in \(\textbf{G}\) is adjacent to an edge in both \(G_2\) and \(G_3\), then we have a rainbow triangle. Further, at least \(\sqrt{\alpha _i}n+O(n)\) vertices must be adjacent to an edge of \(G_i\) for \(i\in \{2,3\}\). If \(\textbf{G}\) is a Gallai colouring, we must thus have \(\alpha _3\le (1-\sqrt{\alpha _2})^2+o(1)\), and this is best possible since one could take \(G_2\) and \(G_3\) to be disjoint cliques. Thus we only need in the following to concern ourselves with the case where \(1>\alpha _1\).

Theorem 1.13

There exists a constant \(C>0\) such that for any \((\alpha _1, \alpha _2)\in [0,1)^2\) with \(\alpha _1\ge \alpha _2\), the following hold.

  1. (a)

    If \((\alpha _1, \alpha _2) \in \mathcal {R}'_1\), then letting (xy) be its canonical representation and setting \(\alpha _3:=1-x^2\), we have that:

    1. (i)

      \(\alpha _2 \ge \alpha _3\);

    2. (ii)

      for any \(n\in \mathbb {N}\), if \(\textbf{G}\) is an n-vertex 3-colouring template with \(\vert E(G_i)\vert \ge \alpha _i\left( {\begin{array}{c}n\\ 2\end{array}}\right) +Cn\) for all \(i\in [3]\), then \(\textbf{G}\) contains a rainbow triangle;

    3. (iii)

      for any \(n\in \mathbb {N}\), setting \(a=\lfloor xn\rfloor \), \(b=\lfloor yn \rfloor \) and \(c=n-a-b\), the n-vertex 3-colouring template \(\textbf{F}(a,b,c)\) satisfies \(\vert E(F_i)\vert \ge \alpha _i\left( {\begin{array}{c}n\\ 2\end{array}}\right) -Cn\) and contains no rainbow triangle.

  2. (b)

    If \((\alpha _1, \alpha _2) \in \mathcal {R}_2\), then setting \(\alpha _3:=2-\alpha _1-2\sqrt{\alpha _2}+\alpha _2\), we have that:

    1. (i)

      \(\alpha _2\ge \alpha _3\);

    2. (ii)

      for any \(n\in \mathbb {N}\), if \(\textbf{G}\) is an n-vertex 3-colouring template with \(\vert E(G_i)\vert \ge \alpha _i\left( {\begin{array}{c}n\\ 2\end{array}}\right) +Cn\) for all \(i\in [3]\), then \(\textbf{G}\) contains a rainbow triangle;

    3. (iii)

      for any \(n\in \mathbb {N}\), setting \(a=\lfloor \sqrt{\alpha _2}n \rfloor \), \(b=\lfloor \frac{1-\alpha _1}{2\sqrt{\alpha _2}}n \rfloor \) and \(c=n-a-b\), the n-vertex 3-colouring template \(\textbf{H}(a,b,c)\) satisfies \(\vert E(H_i)\vert \ge \alpha _i\left( {\begin{array}{c}n\\ 2\end{array}}\right) -Cn\) and contains no rainbow triangle.

  3. (c)

    If \((\alpha _1, \alpha _2)\notin \mathcal {R}'_1\cup \mathcal {R}_2\), then \((\alpha _1, \alpha _2, \alpha _2)\) is not a forcing triple.

Remark 1.14

In both case (a) and case (b) any triple \((\alpha _1', \alpha _2', \alpha _3')\) with \(\alpha _i'<\alpha _i\) for every \(i\in \{1,2,3\}\) is not a forcing triple, while every triple \((\alpha _1', \alpha _2', \alpha _3')\) with \(\alpha _i'>\alpha _i\) for every \(i\in \{1,2,3\}\) is a forcing triple.

Remark 1.15

Note that \(\mathcal {R}'_1\) and \(\mathcal {R}_2\) meet along the curve \(\alpha _1=1-2\sqrt{\alpha _2}+2\alpha _2\) from the point \((2-\sqrt{2},\frac{1}{2})\) to the point (1, 1)—indeed, along this curve, it is easily checked that the canonical representation of \((\alpha _1, \alpha _2)\) is (xy) where \(x=\sqrt{\alpha _1-(1-\sqrt{\alpha _2})^2} = \sqrt{\alpha _2}\) and \(y=1-\sqrt{\alpha _2}\), and satisfies \(2x^2+(1-x-y)^2=2\alpha _2\ge 1\). For \((\alpha _1, \alpha _2)\) along this curve, our extremal 3-colouring templates \(\textbf{H}\) and \(\textbf{F}\) both have \(\vert C\vert =o(n)\) and (up to changing at most \(o(n^2)\) edges into non-edges and vice versa in each of the colour classes) degenerate down to the same 3-colouring template \(\textbf{G}\) on \(A\sqcup B=[n]\) with \(\vert A\vert =\lfloor \sqrt{\alpha _2}n\rfloor \), \(\vert B\vert =n-\vert A\vert \) and colour classes \(G_1= A^{(2)}\cup B^{(2)}\), \(G_2=A^{(2)}\) and \(G_3=[n]^{(2)}{\setminus } A^{(2)}\).

As a consequence of Theorem 1.13, we settle Conjecture 1.9:

Corollary 1.16

Conjecture 1.9 is true.

1.2 Further Remarks and Open Problems

Minimum degree conditions: in both of our extremal colouring templates \(\textbf{F}\) and \(\textbf{H}\), there are colour classes with isolated vertices. Indeed, we have \(\delta (F_1) = \delta (F_2) = 0\) (by considering vertices in C and B respectively) and \(\delta (G_2)=0\) (by considering vertices in \(B\cup C\)). Given this, it is natural to ask how Problem 1.7 changes when we impose minim-degree rather than density conditions.

We study this question in a companion paper [11], in which given \(\delta (G_1)\) we determine the maximum possible value of \(\delta (G_2)+\delta (G_3)\) in a Gallai colouring template \(\textbf{G}\). It turns out the extremal behaviour for this problem is starkly different from the one we established for Problem 1.7 in this paper. Indeed, the maximum possible value of \(\delta (G_2) + \delta (G_3)\) jumps from \(\frac{2n}{r}\) to \(\frac{2n}{r+1}\) when \(\delta _1(G)\) increases from \(n-\lceil \frac{n}{r}\rceil \) to \(\lceil n-\frac{n}{r}\rceil +1\), in contrast to the more continuous behaviour seen in Theorem 1.13.

Other cliques: in [1], Aharoni, DeVos, de la Maza, Montejano and Šámal asked what happens when the triangle \(K_3\) is replaced with a complete graph \(K_r\) on r vertices when \(r \ge 4\).

Question 1.17

Let \(r \ge 4\). What is the smallest real number \(\delta _r\) so that for all n sufficiently large, any n-vertex \({r \atopwithdelims ()2}\)-colouring template \(\textbf{G}\) with \(\min \left\{ \vert E(G_1) \vert , \dots , \vert E(G_{{r \atopwithdelims ()2}})\vert \right\} > \delta _r \frac{n^2}{2}\) must contain a rainbow copy of \(K_{r}\)?

By considering \(G_1=G_2=\cdots = G_{\left( {\begin{array}{c}r\\ 2\end{array}}\right) }=T_{r-1}(n)\), the \((r-1)\)-partite Turán graph, it is clear \(\delta _r \ge 1 - \frac{1}{r-1}\). Is this bound tight for any r?

Other graphs: besides larger cliques, one can ask for conditions guaranteeing the existence of rainbow copies of some other graph H. Babiński and Grzesik [3] recently considered this problem when \(H = P_3\), the path on 4 vertices with 3 edges. For every \(r\ge 3\), they determined the value of the least \(\alpha (r, P_3)\ge 0\) such that for all \(\alpha >\alpha (r, P_3)\) and all n sufficiently large, every n-vertex r-colouring template \(\textbf{G}\) with \(\min \left( \vert E(G_1) \vert , \cdots , \vert E(G_r) \vert \right) \ge \alpha n^2\) must contain a rainbow \(P_3\).

In a similar direction, Frankl, Győri, He, Lv, Salia, Tompkins, Varga and Zhu [14] successfully determined the (asymptotic behaviour of the) maximum of the geometric mean of the colour classes in r-colouring templates with no rainbow copy of H when \(r\in \{3,4\}\) and \(H=P_3\) and when \(r=4\) and \(H=P_4\), the path on five vertices. It would be interesting to obtain generalisation of both of these results for longer paths.

Stability, colourings vs templates: we expect that the proof of Theorem  1.13 can be adapted to give stability versions of our results, but we had not explored this further due to the length of the paper. Finally, we focused in this work on colouring templates, in which colour classes may overlap. Following Erdős and Tuza [10], one could instead consider analogous problems for colourings of \(K_n\) or of subgraphs of \(K_n\). Can one obtain analogues of Theorem 1.13 in this setting?

1.3 Notation

As noted above, we write \([n]:=\{1,2,\ldots n\}\), \(S^{(2)}:=\{\{s,s'\}:\ s,s' \in S, s\ne s'\}\) and \((S,T)^{(2)}:=\{\{s,t\}: \ s\in S, t\in T\}\). Where convenient, we identify \(G_i\) with its edge-set \(E(G_i)\). We also write xy for \(\{x,y\}\). We use \(G_i[X]\) and \(G_i[X,Y]\) as a notation for the subgraph of \(G_i\) induced by the vertex-set X and for the bipartite subgraph of \(G_i\) induced by the bipartition \(X\sqcup Y\) respectively. Throughout the remainder of the paper, we shall use \(\vert G_i\vert \), \(\vert G_i[X]\vert \) and \(\vert G_i[X,Y]\vert \) as shorthands for \(\vert E(G_i)\vert \), \(\vert E(G_i[X])\vert \) and \(\vert E(G_i[X,Y])\vert \) respectively. We use Landau big O notation, and note that \(g=O(f)\) or \(g=o(f)\) is an assertion about the order of g and not its sign (so we do not differentiate between \(1-o(1)\) and \(1+o(1)\), for example).

Given a 3-colouring template \(\textbf{G}\) on a set V, we call a pair \(xy\in V^{(2)}\) a rainbow edge if \(xy\in \bigcap _{i=1}^3G_i\). Further, we call a pair xy which is contained in at least two of the colour classes \(G_1, G_2, G_3\) a bi-chromatic edge. The following notion of density for a colouring template will be a useful tool in our analysis:

Definition 1.18

(Colour density vector) Given an r-colouring template \(\textbf{G}=(G_1, G_2, \ldots , G_r)\) on an n-set V, the colour density vector of \(\textbf{G}\) is

$$\begin{aligned} \mathbf {\rho }(\textbf{G}):=\left( \frac{\vert G_1\vert }{\left( {\begin{array}{c}n\\ 2\end{array}}\right) },\ \frac{\vert G_2\vert }{\left( {\begin{array}{c}n\\ 2\end{array}}\right) },\ \ldots , \ \frac{\vert G_r\vert }{\left( {\begin{array}{c}n\\ 2\end{array}}\right) }\right) . \end{aligned}$$

2 Critical Colour Densities for Rainbow Triangles

2.1 Preliminary Remarks

We begin by analysing the colour density vectors yielded by Constructions 1.5 and 1.8.

Proposition 2.1

For \(a=xn\), \(b=yn\) and \(c=zn\), the colour density vectors of \(\textbf{F}\) and \(\textbf{H}\) are

$$\begin{aligned} \left( x^2+y^2, \ x^2+z^2,\ 1-x^2 \right) + \left( O(n^{-1}),\ O(n^{-1}),\ O(n^{-1})\right) \end{aligned}$$

and

$$\begin{aligned} \left( 1-2xy,\ x^2,\ (1-x)^2 +2xy\right) + \left( O(n^{-1}),\ O(n^{-1}),\ O(n^{-1})\right) \end{aligned}$$

respectively. In particular, for \(z=0\) (and thus \(x+y=1\)) they coincide asymptotically and are both equal to \( \left( x^2+(1-x)^2,\ x^2,\ 1-x^2\right) + \left( O(n^{-1}),\ O(n^{-1}),\ O(n^{-1})\right) \).

Proof

Simple calculation. \(\square \)

Recall that \(\tau =\frac{4-\sqrt{7}}{9}\). The next two propositions establish that certain \((\alpha _1, \alpha _2, \alpha _3)\) are trivially not forcing triples and that for \((\alpha _1, \alpha _2)\) there exists a unique canonical representation \(\alpha _1=x^2+y^2\), \(\alpha _2=x^2+z^2\) with \(x\ge 1/2\), \(0\le y \le 1-x\) and \(x+y+z=1\).

Proposition 2.2

Let \((\alpha _1, \alpha _2, \alpha _3)\) be a triple of elements of [0, 1] with \(\alpha _1\ge \alpha _2\ge \alpha _3\). If any of the following hold, then \((\alpha _1,\alpha _2, \alpha _3)\) is not a forcing triple:

  1. (a)

    \(\alpha _1< \frac{1+\tau ^2}{2}=\frac{52-4\sqrt{7}}{81}\);

  2. (b)

    \(\alpha _2<\frac{1}{4}\);

  3. (c)

    \(\alpha _1+\alpha _2<1\);

  4. (d)

    \(\alpha _1=x^2+y^2\) and \(\alpha _2=x^2+(1-x-y)^2\) for some non-negative reals xy with \(x+y\le 1\) and \(2x^2+(1-x-y)^2<1\).

Proof

For each of the four cases (a)–(d), we construct a suitable n-vertex Gallai 3-colouring template based on \(\textbf{F}=\textbf{F}(a,b,c)\) whose colour density vector is coordinate-wise asymptotically strictly greater than \((\alpha _1, \alpha _2, \alpha _3)\) (possibly after rearranging the order of the colours). Since \(\textbf{F}\) is rainbow \(K_3\)-free, this suffices to show that \((\alpha _1, \alpha _2, \alpha _3)\) is not a forcing triple.

Case (a): \(\alpha _1< \frac{1+\tau ^2}{2}\). Set \(a=n-2\lceil \tau n\rceil \), \(b=c=\lceil \tau n\rceil \). Then \(\textbf{F}(a, b,c)\) has asymptotic colour density vector \(\left( \frac{1+\tau ^2}{2}\right) \cdot (1,1,1)\). For \(\varepsilon >0\) chosen sufficient small, this is pointwise strictly greater than \((\alpha _1, \alpha _2, \alpha _3)+\varepsilon \cdot (1,1,1)\). Thus \((\alpha _1,\alpha _2, \alpha _3)\) is not a forcing triple.

Case (b): \(\alpha _2<\frac{1}{4}\). Set \(a=0\), \(b=\lceil \frac{n}{2}\rceil \), \(c=n-b\). Then \(\textbf{F}(a, b, c)\) has asymptotic colour density vector \((\frac{1}{4},\frac{1}{4},1)\). For \(\varepsilon >0\) chosen sufficiently small, this is pointwise strictly greater than \((\alpha _2, \alpha _3, \alpha _1)+\varepsilon \cdot (1,1,0)\) (since \(\alpha _3\le \alpha _2\)). Rearranging colours, it immediately follows that \((\alpha _1,\alpha _2, \alpha _3)\) is not a forcing triple.

Case (c): \(\alpha _1+\alpha _2<1\). Pick \(\varepsilon >0\) sufficiently small so that \(1-\alpha _2-4\varepsilon >\alpha _1\). Set \(a=\lceil n\sqrt{\alpha _2 +2\varepsilon }\rceil \), \(b=n-a\), \(c=0\). Then \(\textbf{F}(a, b, c)\) has asymptotic colour density vector \((\alpha _2+2\varepsilon +(1-\sqrt{\alpha _2+2\varepsilon })^2, \alpha _2+2\varepsilon , 1-\alpha _2-2\varepsilon )\), which is strictly greater than \((\alpha _2, \alpha _3, \alpha _1)+\varepsilon \cdot (1,1,1)\). Rearranging colours, it immediately follows that \((\alpha _1,\alpha _2, \alpha _3)\) is not a forcing triple.

Case (d): \(\alpha _1=x^2+y^2\), \(\alpha _2=x^2+(1-x-y)^2\) and \(\alpha _2+x^2<1\). Observe that \(2x^2<1\), whence \(x<1/\sqrt{2}\). Since \(\alpha _1\ge \alpha _2\), this implies \(y\ge (1-x)/2>0\). Further, by Case (c) above, we may assume \(1\le \alpha _1+\alpha _2\); since \(\alpha _1+\alpha _2 \le 2x^2+(1-x)^2\), we deduce from this that \(x\ge 2/3\) and in particular \(x>y\).

Pick \(\varepsilon \): \(0<\varepsilon <y\) sufficiently small so that \(\alpha _2+\varepsilon ^2<1-(x+\varepsilon )^2\). Then for \(a=\lfloor (x+\varepsilon )n \rfloor \), \(b=\lfloor (y-\varepsilon )n\rfloor \) and \(c= n-a-b\), the 3-colouring template \(\textbf{F}(a,b,c)\) contains no rainbow triangles and has asymptotic colour density vector \(((x+\varepsilon )^2+ (y-\varepsilon )^2, (x+\varepsilon )^2+(1-x-y)^2, 1- (x+\varepsilon )^2)\), which is pointwise strictly greater than \((\alpha _1, \alpha _2, \alpha _2)+ \varepsilon ^2 \cdot (2,1,1)\) (here in the first coordinate we used the fact that \(x> y\)). Since \(\alpha _2\ge \alpha _3\), it immediately follows that \((\alpha _1,\alpha _2, \alpha _3)\) is not a forcing triple. \(\square \)

Proposition 2.3

Given non-negative real numbers \(\alpha _1, \alpha _2\) satisfying \(\alpha _1\ge \frac{1}{2}\) and \(\frac{\alpha _1+\sqrt{2\alpha _1-1}}{2}\le \alpha _2\le \alpha _1\), there exist a unique triple \((x,y, z)\in [0,1]^3\) with \(x+y+z=1\) and \(x\ge \frac{1}{2}\) such that

$$\begin{aligned} \alpha _1= x^2+y^2{} & {} \alpha _2 = x^2+z^2. \end{aligned}$$
(2.1)

Proof

Set \(y(x):=\sqrt{\alpha _1-x^2}\) and \(z(x):=1-x-y(x)\). Our goal is to show there exists a unique solution \(x_{\star }\) to \(x^2+(z(x))^2=\alpha _2\) with \(x\ge \frac{1}{2}\), y(x) real and \(z(x)\ge 0\).

Solving the appropriate quadratic equations, it is easily checked that for \(x\in [\frac{1}{2},1]\) we have \(z(x)\ge 0\) for \(x\ge x_0= \frac{1+\sqrt{2\alpha _1-1}}{2}\) and \(y(x)\ge z(x)\) for \(x\le x_1=\frac{1+2\sqrt{5\alpha _1-1}}{5}\). It is clear geometrically that \(x_0\le x_1\) (these values of x corresponding as they do to intersections of the circle \(x^2+y^2=\alpha _1\) with the lines \(y=1-x\) and \(y=(1-x)/2\) in the first quadrant of the plane). Further, solving another two quadratic equations, it is easily checked that \(x_1\le \sqrt{\alpha _1}\) with equality if and only if \(\alpha _1=1\), so that y(x) is real in the interval \([x_0, x_1]\).

Now, \((x_0)^2+(z(x_0))^2=(x_0)^2=\frac{\alpha _1+\sqrt{2\alpha _1-1}}{2}\le \alpha _2\) and \((x_1)^2+(z(x_1))^2=(x_1)^2+(y(x_1))^2=\alpha _1\ge \alpha _2\). The existence of an \(x_{\star }\in [x_0, x_1]\) such that \((x_{\star })^2 +(z(x_{\star }))^2=\alpha _2\) thus follows from the intermediate value theorem.

It remains to show the uniqueness of this solution. Suppose there exists \(x=x_{\star }+d_x\) for some \(d_x\ge 0\) and yz with \(x+y+z=1\) such that (xyz) satisfies (2.1). Clearly we must have \(y = y(x_\star )-d_y\) and \(z = z(x_{\star })-d_z\) for some non-negative \(d_y, d_z\) with \(d_x=d_y+d_z\) (otherwise one of the equations in (2.1) or the condition \(x+y+z=1\) must fail). Since \(x\ge \frac{1}{2}\) we have \(y\le \frac{1}{2}\) and \((x_{\star }+d_x)^2+(y(x_{\star })-d_y)^2\ge (x_{\star })^2+(y(x_{\star }))^2 +(d_x-d_y)\). In particular, \(d_y\ge d_x\). Then \(d_x=d_y+d_z\) implies \(d_z=0\), which in turn implies \(d_x=0\) (else \(x^2+z^2>(x_{\star })^2 +(z(x_{\star }))^2\)) and hence \(d_y=0\), and the uniqueness of our triple \((x_{\star },y(x_{\star }),z(x_{\star }))\). \(\square \)

Definition 2.4

(Good pair) We say that a pair of non-negative real numbers \((\alpha _1,\alpha _2)\) from \([0,1]^2\) is a good pair if

$$\begin{aligned} \max \left\{ \frac{1}{4}, \frac{\alpha _1+\sqrt{2\alpha _1-1}}{2}\right\} \le \alpha _2{} & {} \max \left\{ \alpha _2, 1-\alpha _2, \frac{1+\tau ^2}{2} \right\} \le \alpha _1, \end{aligned}$$

and in addition the unique \((x,y,z)\in [0,1]^3\) with \(x+y+z=1\) and \(x\ge \frac{1}{2}\) such that (2.1) holds satisfies \(2x^2+z^2\ge 1\). Given a good pair, we refer to this unique (xyz) (whose existence is guaranteed by Proposition 2.3) as the canonical representation of \((\alpha _1, \alpha _2)\).

2.2 Proof Strategy

We divide the proof of Theorem 1.13 into two parts, depending on whether or not the edge densities \(\alpha _1\) and \(\alpha _2\) of the two largest colour classes satisfy \(\alpha _1 \le \alpha _2+ (1-\sqrt{\alpha _2})^2\). In both cases, we prove a technical statement of the form ‘if the colour classes of a colouring template satisfy certain inequalities, then it must contain a rainbow triangle’. To do so, we consider a putative minimal counterexample \(\textbf{G}\) to our technical statement, and use its minimality to rule out the existence of rainbow edges.

We then consider a largest matching M of bi-chromatic edges in \(\textbf{G}\), which we use to obtain a partition of \(V=V(\textbf{G})\) into sets \(V_{ij}\) of vertices meeting a bi-chromatic edge of M in colours ij and a left-over set D. We perform a series of modification of \(\textbf{G}\) to obtain a new colouring template \(\mathbf {G''}\) such that the sizes of the colour classes of \(\mathbf {G''}\) satisfy the same inequalities as those of \(\textbf{G}\) up to some small O(n) error terms. The crux is, however, that \(\mathbf {G''}\) is very well-structured with respect to the partition obtained in the previous step, so that we have a good control over the sizes of its colour classes. In the final step of the argument, we use this information to derive a contradiction from our family of inequalities.

The idea of considering a largest matching of bi-chromatic edges and modifying \(\textbf{G}\) based on the resulting partition appeared previously in the work of Aharoni, DeVos, de la Maza, Montejanos and Šámal [1], more specifically their key Lemma 2.3 which inspired our approach in the case \(\alpha _1 \le \alpha _2+ (1-\sqrt{\alpha _2})^2\).

An important additional ingredient in our proof in the case \(\alpha _1 > \alpha _2+ (1-\sqrt{\alpha _2})^2\) is the idea of looking a vertex-minimal counterexample \(\textbf{G}\) which also maximises the size of the largest colour class \(G_1\). Indeed, this allows us to ‘push’ \(\textbf{G}\) towards a much more amenable bipartite extremal structure, which we are able to analyse.

2.3 The \(\textbf{F}\)-Extremal Region: The Case \(\alpha _1\le \alpha _2 +(1-\sqrt{\alpha _2})^2\)

Note that for \(\alpha _1\ge 1/2\) and \(\alpha _2\ge 1/4\), the inequality for \(\alpha _1, \alpha _2\) we have in this case is equivalent to the lower bound for \(\alpha _2\) we had in our definition of a good pair in Sect. 2.1:

$$\begin{aligned} \alpha _2\le \alpha _1\le \alpha _2 +(1-\sqrt{\alpha _2})^2{} & {} \Leftrightarrow{} & {} \frac{\alpha _1+\sqrt{2\alpha _1-1}}{2}\le \alpha _2\le \alpha _1. \end{aligned}$$
(2.2)

Theorem 2.5

Let \((\alpha _1, \alpha _2)\) be a good pair and let (xyz) be its associated canonical representation. Set \(\alpha _3:= 1-x^2\). If \(\textbf{G}\) is a 3-colouring template on n vertices satisfying

$$\begin{aligned} \vert E(G_i)\vert +\vert E(G_j)\vert \ge \left( \alpha _i+\alpha _j\right) \left( {\begin{array}{c}n\\ 2\end{array}}\right) +5n \end{aligned}$$
(2.3)

for all distinct \(i, j \in [3]\), then \(\textbf{G}\) contains a rainbow triangle.

Proof

Observe that for \(n\le 6\), the statement of Theorem 2.5 is vacuous, since \(5n\ge 2\left( {\begin{array}{c}n\\ 2\end{array}}\right) \). Suppose Theorem 2.5 is false, and let \(N\ge 7\) be the least value of n for which there exists a Gallai 3-colouring template \(\textbf{G}\) which provides a counterexample. Without loss of generality, we may assume the vertex-set of \(\textbf{G}\) is \(V=[N]\). We begin our proof with an analogue of [1, Lemma 2.4], which establishes inter alia that there are no rainbow edges. \(\square \)

Lemma 2.6

For every non-empty proper subset X of V, at least one of the induced subgraphs \(G_i[X]\), \(i\in [3]\), fails to contain a perfect matching.

Proof

Let X be a \(2\ell \)-set in V with \(0<\ell <N/2\). Suppose for a contradiction that the graphs \(G_1[X]\), \(G_2[X]\) and \(G_3[X]\) contain perfect matchings \(M_1\), \(M_2\) and \(M_3\) respectively. We shall bound \(\vert G_i[V\setminus X]\vert +\vert G_j[V\setminus X]\) for all distinct colour pairs \(ij\in [3]^{(2)}\).

Fix a colour \(k\in [3]\), and let ij denote the other two colours in [3]. Let \(vv'\) be an edge of \(M_k\). Then every vertex \(u \in V{\setminus } X\) can send at most 2 edges in colour i or j to \(\{x,x'\}\) (for otherwise we have a rainbow triangle). Summing over all edges of \(M_3\), it follows that

$$\begin{aligned} \vert G_i[X, \!V\setminus X]\vert \! +\! \vert \!G_j[X, \!V\!\setminus \! X]\vert&\le \! \sum _{vv'\in M_k} \!\left( \vert G_i[\{v,v'\}, V\setminus X]\vert \!+\vert G_j[\{v,v'\}, \!V\setminus X]\vert \right) \nonumber \\&\le 2\ell (N-2\ell ). \end{aligned}$$
(2.4)

Next we show that \(\vert G_i[X]\vert + \vert G_j[X]\vert \le 2\ell ^2\). If \(\ell =1\), we have nothing to show since \(2\left( {\begin{array}{c}2l\\ 2\end{array}}\right) =2\ell ^2\). On the other hand if \(\ell \ge 2\), then consider an edge \(uu' \in (G_i\cap G_j)[X]\setminus M_k\). Since \(M_k\) is a perfect matching and \(uu'\notin M_k\), there exist distinct \(v,v' \in X\setminus \{u,u'\}\) such that \(uv, u'v'\in M_k\). This in turn implies that \(uv', u'v \notin (G_i\cup G_j)[X]{\setminus } M_k\) (since otherwise one of the sets \(\{u,u',v'\}\), \(\{u,u',v\}\) would contain a rainbow triangle). Note that the vertices \(v,v'\) are uniquely specified by \(uu'\) and the matching \(M_k\).

Thus given any \(uu'\in X^{(2)}\setminus M_k\) we can define a pair of edges \(F(uu')=\{uv', u'v\}\), with \(v,v'\) as above, such that either \(uu'\notin G_i\cap G_j\) or \(uv', u'v \notin G_i\cup G_j\). Observe that \(F(uu')\cap F(ww')\ne \emptyset \) if and only if \(M_k\) contains a matching from \(\{u,u'\}\) to \(\{w,w'\}\) (i.e. if and only if \(ww'=vv'\)), in which case \(F(uu')=F(ww')\). In particular we have that \(\vert (G_i\cap G_j)[X]{\setminus } M_k \vert \le \vert X^{(2)}{\setminus } (G_i\cup G_j \cup M_k)\vert \) and thus

$$\begin{aligned} \vert G_i[X]\vert +\vert G_j[X]\vert&\le 2\vert M_k\vert + \vert (G_i\cup G_j)[X]\setminus M_k\vert +\vert (G_i\cap G_j)[X]\setminus M_k\vert \nonumber \\&\le 2\ell +\left( \left( {\begin{array}{c}2\ell \\ 2\end{array}}\right) -\ell \right) =2\ell ^2. \end{aligned}$$
(2.5)

Putting (2.4) and (2.5) together, we have

$$\begin{aligned} \vert G_i[V\setminus X]\vert +\vert G_j[V\setminus X]\vert&= \vert G_i\vert -\vert G_i[X, V \setminus X]\vert -\vert G_i[X]\vert + \vert G_j\vert \nonumber \\&\quad -\vert G_j[X, V \setminus X]\vert -\vert G_j[X]\vert \nonumber \\&\ge \left( \alpha _i +\alpha _j\right) \left( {\begin{array}{c}N\\ 2\end{array}}\right) +5N-2\ell (N-2\ell ) -2\ell ^2. \end{aligned}$$
(2.6)

\(\square \)

Claim 2.7

\(\left( \alpha _i +\alpha _j\right) \left( {\begin{array}{c}N\\ 2\end{array}}\right) +5N-2\ell (N-2\ell ) -2\ell ^2\ge \left( \alpha _i +\alpha _j\right) \left( {\begin{array}{c}N-2\ell \\ 2\end{array}}\right) +5(N-2\ell )\).

Proof

Rearranging terms, what we must show is

$$\begin{aligned} \left( \alpha _{i}+\alpha _{j}-1\right) 2\ell \left( N-\ell \right) +\left( 10-\alpha _{i}-\alpha _{j}\right) \ell \ge 0. \end{aligned}$$
(2.7)

Note first of all that \(\alpha _i+\alpha _j\ge 1\). Indeed, since \((\alpha _1, \alpha _2)\) is a good pair, this is by definition the case for \(\{i,j\}=\{1,2\}\). Further, the definition of \(\alpha _3:=1-x^2\) ensures \(\alpha _1+\alpha _3=1+y^2\) and \(\alpha _2+\alpha _3=1+z^2\) are both at least 1. Now, since X was a proper non-empty subset of V, we have \(N>2\ell \), and hence the first term in the sum on the left hand-side of (2.7) is non-negative. As \(\alpha _i+\alpha _j\le 2\), the second term in 2.7 is strictly positive. Thus (2.7) holds, as required. \(\square \)

Since ij were arbitrary, it follows from (2.6) and Claim 2.7 that \(\textbf{G}[V\setminus X]\) is a Gallai 3-colouring template on \(n=N-\vert X\vert < N\) vertices satisfying (2.3), and hence a smaller counterexample to Theorem 2.5, contradicting the minimality of N. \(\square \)

As in [1], we have the following corollary to Lemma 2.6:

Proposition 2.8

(Observation 2.5 in [1]) Let \(xx'\) and \(yy'\) be vertex-disjoint pairs from \(V^{(2)}\). Let \(\{i,j,k\}=[3]\). Then the following hold:

  1. 1.

    if \(xx', yy' \in G_i\cap G_j\), then either

    1. (a)

      \(\vert G_k[xx', yy']\vert =0\), or

    2. (b)

      \(\vert G_k[xx', yy']\vert =1\) and \(\vert G_i[xx', yy']\vert , \vert G_j[xx', yy']\vert \le 2\), or

    3. (c)

      \(\vert G_k[xx', yy']\vert =2\) and \(\vert G_i[xx', yy']\vert =\vert G_j[xx', yy']\vert =0\);

  2. 2.

    if \(xx'\in G_i\cap G_j\) and \(yy'\in G_i\cap G_k\), then either

    1. (a)

      \(\sum _{i=1}^3 \vert G_i[xx, yy']\vert \le 4\), or

    2. (b)

      \(\vert G_i[xx', yy']\vert =3\), \(\vert G_j[xx', yy']\vert =\vert G_j[xx', yy']\vert =1\), this latter possibility occurring if and only if we have (up to permutations of the pairs jk, \(xx'\) and \(yy'\)) \(xy\in G_i\cap G_k\), \(x'y'\in G_i\cap G_j\) and \(xy'\in G_i\).

Proof

Identical to the (simple case analysis in the) proof of [1, Observation 2.5] but with our Lemma 2.6 replacing [1, Lemma 2.4]. \(\square \)

Still following Aharoni et al’s approach from [1], we consider a largest matching M of bi-chromatic edges (called digons in [1]), to obtain a partition of the vertex set. For \(ij\in [3]^{(2)}\), set \(M_{ij}:=M\cap G_i\cap G_j\), and let \(V_{ij}\) denote the collection of vertices contained in an edge of \(M_{ij}\). Set \(D:=V{\setminus } \left( V_{13}\sqcup V_{23}\sqcup V_{23}\right) \) to be the set of vertices not contained in an edge of M. As observed by Aharoni et al, one can perform some local modifications of \(\textbf{G}\) to obtain a new colouring template \(\textbf{G}''\) which is well-structured with respect to the partition \(V=V_{13}\sqcup V_{12}\sqcup V_{23}\sqcup D\), may possibly contain rainbow triangles, but importantly satisfies the bounds (2.3) up to a small correction term which is linear in N. More explicitly, combining [1, Claims 1–3], one obtains the following:

Proposition 2.9

(Claims 1–3 in [1]) There exists a 3-colouring template \(\mathbf {G''}\) on V such that the following hold:

  1. (i)

    the bound \(\vert G''_{i}\vert +\vert G''_{j}\vert \ge \vert G_{i}\vert +\vert G_{j}\vert -\frac{3}{2}N > \left( \alpha _{i}+\alpha _{j}\right) \left( {\begin{array}{c}N\\ 2\end{array}}\right) +2N\) holds for all distinct i and j;

  2. (ii)

    \(\bigcap _{i=1}^3 G''_i=\emptyset \) (i.e. there are no rainbow edges)

  3. (iii)

    for all \(ij\in [3]^{(2)}\), \((G''_i\cap G_j'')[V_{ij}]={(V_{ij})}^{(2)}\) (i.e. \(V_{ij}\) induces a bi-chromatic clique of edges in colours i and j, and thus by condition (ii) above contains no edge in the third colour);

  4. (iv)

    there are no bi-chromatic edges inside D or between distinct sets \(V_{ij}\), \(ij\in [3]^{(2)}\);

  5. (v)

    if \(y\in D\) and \(xx'\) is an edge in \(M_{ij}=M\cap {(V_{ij})}^{(2)}\), then \(\vert G''_1[\{y\},\{x,x'\}]\vert + \vert G''_2[\{y\}, \{x,x'\}]\vert +\vert G''_3[\{y\},\{x,x'\}]\vert \le 3\), with equality if and only if \(\vert G''_i[\{y\}, \{x,x'\}]\vert + \vert G''_j[\{y\}, \{x,x'\}]\vert =3\).

Proof

Immediate from the construction of the modified colour classes \(G''_i\), \(i\in [3]\) in [1, Claims 1–3] (which only rely on Lemma 2.6, Proposition 2.8 and the self-contained graph theoretic lemma [1, Lemma 2.2]). Note that we started out with a slightly larger linear term in our inequality (2.3), whence the slightly larger term in the expression to the right of the last inequality in condition (i). \(\square \)

Set \(a_{ij}:=\vert V_{ij}\vert /N\) and \(d:=\vert D\vert /N\). We are now ready to proceed with the last part of the proof of Theorem 2.5, where we use the structure of the colouring template \(\textbf{G}''\) to derive upper bounds for the sizes of its colour classes in terms of \((a_{12}, a_{13}, a_{23}, d)\) (Lemma 2.10 below), which we then show contradict the lower bounds from Proposition 2.9(i) (Lemma 2.12 below). Lemma 2.12 is also the point in the proof of Theorem 2.5 where we depart from the approach of Aharoni et al. [1].

Lemma 2.10

The following inequalities are satisfied:

$$\begin{aligned}&a_{12}(a_{12}+d)> \alpha _1+\alpha _2-1=2x^2+y^2+z^2-1 , \end{aligned}$$
(2.8)
$$\begin{aligned}&a_{13}(a_{13}+d)> \alpha _1+\alpha _3-1= y^2 , \end{aligned}$$
(2.9)
$$\begin{aligned}&a_{23}(a_{23}+d)> \alpha _2+\alpha _3-1 =z^2 , \end{aligned}$$
(2.10)
$$\begin{aligned}&\sum _{ij} a_{ij}(a_{ij} + d) > \alpha _1+\alpha _2+\alpha _3-1=x^2+y^2+z^2 \end{aligned}$$
(2.11)
$$\begin{aligned}&(a_{12})^2 + 2(a_{13})^2 + 2(a_{23})^2 + 2a_{13}d + 2a_{23}d > 2\alpha _{1} + 2\alpha _{2} + 3\alpha _{3} -3\nonumber \\&\quad = x^2 + 2y^2 + 2z^2, \end{aligned}$$
(2.12)
$$\begin{aligned}&2(a_{12})^2 + (a_{13})^2 + 2(a_{23})^2 + 2a_{12}d + 2a_{23}d > 2\alpha _{1} + 3\alpha _{2} + 2\alpha _{3}-3, \end{aligned}$$
(2.13)
$$\begin{aligned}&2(a_{12})^2 + 2(a_{13})^2 + (a_{23})^2 + 2a_{12}d + 2a_{13}d > 3\alpha _{1} + 2\alpha _{2} + 2\alpha _{3}-3. \end{aligned}$$
(2.14)

Proof

For inequality (2.8), we bound the sum of the number of edges in colours 1 and 2. Clearly a pair of vertices from V can contribute at most 2 to the sum \(\vert G''_1\vert +\vert G''_2\vert \). However by Proposition 2.9(iii) and (iv), pairs of vertices from \(\left( V_{13}\right) ^{(2)}\), \(\left( V_{23}\right) ^{(2)}\) and \(D^{(2)}\) contribute at most 1 to this sum. Further, by Proposition 2.9(iv), a vertex-pair \(xx'\) with x, \(x'\) coming from two different sets \(V_{ij}\) can contribute at most 1 to this sum. Finally, by Proposition 2.9(v), each edge from \(M_{13}\) or \(M_{23}\) sends at most two edges in colours 1 or 2 to a vertex \(y\in D\), while each edge of \(M_{12}\) sends at most three edges in colours 1 or 2 to a vertex \(y\in D\). Summing over all such edges, we see that the total contribution to \(\vert G''_1\vert +\vert G''_2\vert \) from vertex pairs xy with \(x\in V_{13}\cup V_{23}\) and \(y\in D\) is at most \(\left( \vert V_{13}\vert + \vert V_{23}\vert \right) \cdot \vert D\vert \), while the contribution from pairs xy with \(x\in V_{12}\) and \(y\in D\) is at most \(\frac{3}{2} \vert V_{12} \vert \cdot \vert D\vert \). It follows from this analysis that

$$\begin{aligned} \vert G''_1\vert +\vert G''_2\vert\le & {} \left( {\begin{array}{c}N\\ 2\end{array}}\right) + \left( {\begin{array}{c}\vert V_{12}\vert \\ 2\end{array}}\right) +\frac{1}{2}\vert V_{12}\vert \cdot \vert D\vert = \left( {\begin{array}{c}N\\ 2\end{array}}\right) +\left( {\begin{array}{c}a_{12}N\\ 2\end{array}}\right) +\frac{1}{2}a_{12}dN^2 \\< & {} \left( {\begin{array}{c}N\\ 2\end{array}}\right) \left( 1 + a_{12}(a_{12}+d)\right) +N. \end{aligned}$$

Combining this upper bound with the lower bound for \(\vert G''_1\vert +\vert G''_2\vert \) from Proposition 2.9(i), subtracting N from both sides and dividing through by \(\left( {\begin{array}{c}N\\ 2\end{array}}\right) \), we get the desired inequality (2.8). Inequalities (2.9) and (2.10) are obtained in the same way, mutatis mutandis.

Next we turn our attention to the proof of inequality (2.11). This is done by bounding the number of edges in colours 1, 2 and 3. We see that each pair \(xx'\) contributes at most one to the sum \(\sum _{i}\vert G''_{i}\vert \), with two exceptions. If \(x,x'\in V_{ij}\), then \(xx'\) is a bi-chromatic edge and contributes 2 to this sum. Finally, some pairs \(x\in V_{ij}\), \(y\in D\) may also contribute up to 2 to this sum; we bound the contribution of those pairs by appealing to Proposition 2.9(v) which implies that for each pair \(xx'\) from \(M_{ij}\), the sum of the contributions from xy and \(x'y\) to \(\sum _{i} \vert G''_i\vert \) is at most 3. Summing over all \(\vert M_{ij}\vert = \vert V_{ij}\vert /2\) pairs \(xx'\in M_{ij}\), we get

$$\begin{aligned} \sum _i \vert G''_i\vert&\le \left( {\begin{array}{c}N\\ 2\end{array}}\right) + \sum _{ij} \left( \left( {\begin{array}{c}\vert V_{ij}\vert \\ 2\end{array}}\right) +\frac{1}{2}\vert M_{ij}\vert \cdot \vert D\vert \right) \nonumber \\&< \left( {\begin{array}{c}N\\ 2\end{array}}\right) \left( 1+\sum _{ij} \left( (a_{ij})^2 +a_{ij}d \right) \right) +3N. \end{aligned}$$
(2.15)

On the other hand, summing up the lower bounds for \(\vert G''_i\vert + \vert G''_j\vert \) we get from Proposition 2.9(i) for all three pairs \(ij\in [3]^{(2)}\), we have

$$\begin{aligned} 2\sum _i \vert G''_i\vert \ge 2\left( \sum _i\alpha _i\right) \left( {\begin{array}{c}N\\ 2\end{array}}\right) +6N \end{aligned}$$

Now, \(\sum _{i}\alpha _i= x^2+y^2+z^2+1\), so combining this lower bound with the upper bound in (2.15), we get the desired inequality (2.11).

Inequalities (2.12),  (2.13) and (2.14) can be proved similarly. For instance, (2.12) follows by counting edges in \(G''_1\) and \(G''_2\) twice and edges in \(G''_3\) three times, and analysing how many times different types of pairs can be counted in this sum. Inequalities (2.13) and (2.14) can be proved by counting similar linear combinations of the \(\vert G''_i\vert \). \(\square \)

We shall now derive a contradiction from the system of inequalities we have derived (which unfortunately requires a significant amount of careful calculations). To do so, we shall make use of the following simple fact.

Proposition 2.11

Let \(b_{0}\), \(c_{0}\) and s be given non-negative reals satisfying \(c_0\le b_0\) and \(2b_0+c_0\le s\). Then the expression \(a^{2}+b^{2}+c^{2}\) attains its maximum value subject to the conditions \(b\ge b_{0}\), \(c\ge c_{0}\), \(a+b+c=s\) and \(a\ge b\ge c\) uniquely when \(a=s-b_{0}-c_{0}\), \(b=b_{0}\) and \(c=c_{0}\).

Proof

Immediate from the convexity of the function \(x\rightarrow x^{2}\). \(\square \)

Lemma 2.12

Suppose that \(a_{12}\), \(a_{13}\), \(a_{23}\) and d are non-negative real numbers satisfying inequalities (2.8)–(2.14). Then we have \(a_{12} + a_{13} + a_{23} + d > 1\).

Proof

Since \((\alpha _1, \alpha _2)\) is a good pair, we have by definition \(\alpha _1\ge \alpha _2\) and \(\alpha _2-\alpha _3=2x^2+z^2-1\ge 0\), and hence \(\alpha _2\ge \alpha _3\). In particular, the right hand-side in the inequalities (2.8), (2.9) and (2.10) form a decreasing sequence. On the other hand, for d fixed, the expressions on the left hand-side of the inequalities inequalities (2.8), (2.9) and (2.10) are increasing functions of \(a_{12}\), \(a_{13}\) and \(a_{23}\) respectively. Similarly the right-hand sides of the inequalities (2.12), (2.13) and (2.14) form an increasing sequence, and for d fixed, the expressions on the left hand side are increasing functions of \(a_{12}\), \(a_{13}\) and \(a_{23}\) respectively. Since the inequality (2.11) is invariant under any permutation of \((a_{12}, a_{13}, a_{23})\), it follows that we may permute the first three coordinates of \((a_{12}, a_{13}, a_{23}, d)\) to ensure \(a_{12}\ge a_{13}\ge a_{23}\), while still satisfying our constraints and without decreasing the value of \(a_{12} + a_{13} + a_{23} + d\).

We may thus assume \(a_{12}\ge a_{13}\ge a_{23}\) in the remainder of the proof. With this assumption in hand, some of our inequalities become superfluous. Moving forward in the proof, we relax (2.10) to a non-strict inequality and only use (2.9), the relaxed inequality (2.10), (2.11) and (2.12).

Suppose for the sake of contradiction that we have chosen non-negative real numbers \(a_{ij}\) and d so that \(a_{12} + a_{13} + a_{23} + d \le 1\) and the inequalities (2.9), (2.10), (2.11) and (2.12) are satisfied. Given the value of \(a_{13} + a_{23}\), we can increase the value of \(a_{13}\) while decreasing \(a_{23}\) without violating the inequalities (2.9), (2.11) or (2.12), as long as the inequality (2.10) remains satisfied and as long the inequality \(a_{12} \ge a_{13}\) is still satisfied. This is evident from the symmetric role played by the variables \(a_{13}\) and \(a_{23}\) and the convexity of the expressions in (2.11) and (2.12).

Thus we may assume that either \(a_{12} = a_{13}\) or the inequality (2.10) is tight. First let us suppose that \(a_{12} = a_{13}\) and \(a_{12} + a_{13} + a_{23} + d \le 1\). Then it follows that

$$\begin{aligned} \frac{1}{2}\le & {} x^2 + y^2 \le x^2 + y^2 + z^2 \le \sum _{ij} a_{ij}\left( a_{ij} + d\right) \le d(1-d) + \sum _{ij} a_{ij}^{2}\\\le & {} d(1-d) + \left( \frac{1-d}{2}\right) ^2. \end{aligned}$$

However, it is easy to check that the inequality \(d(1-d) + \left( \frac{1-d}{2}\right) ^2 \ge \frac{1}{2}\) is false for every \(d \in [0,1]\), and hence we are done in this case.

Hence we may suppose that the inequality (2.10) is tight, i.e. that we have \((a_{23})^2 + da_{23} = z^2\). Hence it follows that

$$\begin{aligned} a_{23} = \frac{-d + \sqrt{d^2 + 4z^2}}{2}. \end{aligned}$$
(2.16)

Let \(\delta \ge 0\) be chosen so that \(a_{13}^2 + da_{13} = y^2 + \delta \), and note that the non-negativity of \(\delta \) is guaranteed by (2.9). Hence we have

$$\begin{aligned} a_{13} = \frac{-d + \sqrt{d^2 + 4y^2 + 4\delta }}{2}. \end{aligned}$$
(2.17)

Combining this with (2.16), we can simplify the inequalities (2.12) and (2.11) to obtain the following lower bounds for \(a_{12}\):

$$\begin{aligned} a_{12}&> \sqrt{x^2 - 2\delta }, \end{aligned}$$
(2.18)
$$\begin{aligned} (a_{12})^2 +da_{12}&> x^2 - \delta , \qquad \text { implying } \quad a_{12}>\frac{-d+\sqrt{4x^2+d^2-4\delta }}{2}, \end{aligned}$$
(2.19)
$$\begin{aligned} a_{12}&\ge a_{13} = \frac{-d+\sqrt{d^2+4y^2+4\delta }}{2}. \end{aligned}$$
(2.20)

We start by observing that we must have \(d > 0\). Indeed, if \(d = 0\), then (2.16) and  (2.17) imply that \(a_{13} \ge y\) and \(a_{23} = z\). Increasing the value of \(a_{12}\) if necessary, we may assume that \(a_{12} + a_{13} + a_{23} = 1\) without violating (2.11). However, then Proposition 2.11 implies that \(a_{12}^2 + a_{13}^2 + a_{23}^2 \le x^2 + y^2 + z^2\), which contradicts  (2.11). Thus we must have \(d > 0\).

Next, we note that we may assume \(\delta < \frac{x^2 - y^2}{2}\). \(\square \)

Claim 2.13

If \(\delta \ge \frac{x^2 - y^2}{2}\), then \(a_{12} + a_{13} + a_{23} + d > 1\).

Proof

Suppose \(\delta \ge \frac{x^2 - y^2}{2}\). Then (2.17) implies that

$$\begin{aligned} a_{13} \ge \frac{-d + \sqrt{d^2 + 2(x^2 + y^2)}}{2} \end{aligned}$$

Since \((\alpha _1, \alpha _2)\) is a good pair,

$$\begin{aligned} x^2 + y^2 = \alpha _1 \ge \frac{1+\tau ^2}{2} > \frac{1}{2}, \end{aligned}$$

from which we deduce that \(a_{13} > \frac{-d + 1}{2}\). Thus (2.20) implies that we also have \(a_{12} > \frac{-d+1}{2}\), and hence we conclude that \(a_{12} + a_{13} + a_{23} + d > 1\), as required. \(\square \)

Assuming from now on that \(\delta < \frac{x^2 - y^2}{2}\), we make a useful observation on the value of x before splitting our analysis into two cases, depending on which of the two inequalities (2.18) and (2.19) gives the best lower bound for \(a_{12}\).

Claim 2.14

\(x\ge 1-2\tau \).

Proof

Since \((\alpha _1, \alpha _2)\) is a good pair, we have

$$\begin{aligned} 1\le 2x^2 + z^2 \le 2x^2+\left( \frac{1-x}{2}\right) ^2. \end{aligned}$$

Solving the associated quadratic inequality and using the fact that \(x\ge 0\) yields the claimed lower bound on x: \(x\ge \frac{1+2\sqrt{7}}{9}=1-2\tau \). \(\square \)

Case 1: \(0 \le \delta \le d\sqrt{x^2 + d^2} - d^2\). Let us fix \(d>0\), and define the function \(f\left( \delta \right) =f_{x,y,z,d}(\delta )\) for \(\delta \in \left[ 0, d\sqrt{x^2+d^2} - d^2\right] \) by setting

$$\begin{aligned} f\left( \delta \right) :=\sqrt{x^2-2\delta } + \frac{\sqrt{d^2+4y^2+4\delta } + \sqrt{d^2+4z^2}}{2}, \end{aligned}$$

and observe that by (2.18) we have \(a_{12} + a_{13} + a_{23} + d \ge f(\delta )\). Thus our aim is to prove that the least value of f on this interval is strictly greater than 1. The derivative of f can be written as

$$\begin{aligned} f'\left( \delta \right) = \frac{x^2 - 4y^2 -d^2 - 6\delta }{\sqrt{\left( x^2-2\delta \right) \left( d^2+4y^2+4\delta \right) }\left( \sqrt{x^2-2\delta } + \sqrt{d^2+4y^2+4\delta }\right) }. \end{aligned}$$

In particular, there exists a constant \(c = \frac{x^2-4y^2 - d^2}{6}\) so that f is increasing on \(\left[ 0,c\right] \) and f is decreasing on \(\left[ c,d\sqrt{x^2+d^2}-d^2\right] \). Hence f attains its smallest value when \(\delta = 0\) or \(\delta = d\sqrt{x^2+d^2}-d^2\) (note that c may not belong to the interval \(\left[ 0,d\sqrt{x^2+d^2}-d^2\right] \), but the conclusion still remains true). Since \(f(0) = x + \sqrt{y^2 + \frac{d^2}{4}} + \sqrt{z^2 + \frac{d^2}{4}} > x + y + z = 1\), we may turn our attention to analysing \(f\left( d\sqrt{x^2+d^2} - d^2\right) \). It is easy to check that we have

$$\begin{aligned} f\left( d\sqrt{x^2\!+\!d^2} - d^2\right) \!=\! \sqrt{x^2 \!+\! d^2} -d \!+\! \frac{\sqrt{4y^2 \!+\! 4d\sqrt{x^2\!+\!d^2}\!-\!3d^2}+\sqrt{4z^2\!+\!d^2}}{2} . \end{aligned}$$
(2.21)

Let us consider (2.21) with z and d fixed, and varying x and y while keeping \(x+y\) as constant. Set \(s:= x+y\), and note that by Claim 2.14 we have \(x\ge 1-2\tau \) and thus \(s \ge \frac{1+x}{2} \ge 1 - \tau \). Rewriting (2.21) as a function \(g(x)=g_{s,z,d}(x)\) of x, we obtain

$$\begin{aligned} g(x)&:=f\left( d\sqrt{x^2\!\!+d^2}\! -\! d^2\right) \!=\! \sqrt{x^2+d^2}\! -d \!+\! \frac{\sqrt{4(x-s)^2\! + \!4d\sqrt{x^2\!+\!d^2}\!-\!3d^2}}{2} \\&\quad + \frac{\sqrt{4z^2+d^2}}{2} , \end{aligned}$$

whose derivative is given by

$$\begin{aligned} g'(x) = \frac{x}{\sqrt{x^2+d^2}} + \frac{2(x-s) + \frac{xd}{\sqrt{x^2+d^2}}}{\sqrt{4(x-s)^2+4d\sqrt{x^2+d^2}-3d^2}}. \end{aligned}$$

Our aim is to show that \(g'(x)\) is positive for \(1- 2\tau \le x \le 1\). We first note that \(4d\sqrt{x^2+d^2} - 3d^2 > d^2\). Since \(x - s < 0\), we obtain that

$$\begin{aligned} g'(x) \ge \frac{x}{\sqrt{x^2+d^2}} - \frac{2(s-x)}{\sqrt{4(x-s)^2 + d^2}}. \end{aligned}$$

Thus it suffices to prove that \(g'(x) > 0\) in order to deduce that \(x^2\left( 4(s-x)^2 + d^2\right) > 4(s-x)^2 \left( x^2 + d^2\right) \). This follows from the fact that \(2(s-x) - x \le 2(1-x) - x \le 6\tau -1 < 0\). Hence it suffices to prove that \(f\left( d\sqrt{x^2+d^2} - d^2\right) > 1\) when \(x = 1 - 2\tau \) and \(y + z = 2\tau \).

We now substitute the value \(x=1-2\tau \) into (2.21) and set \(h(d)=h_{y,z}(d):=f\left( d\sqrt{(1-2\tau )^2+d^2} - d^2\right) \). By differentiating and using the facts that \(y \le 1-x=2\tau \), that \(z \le \frac{1-x}{2}\le \tau \), and that \(4\sqrt{x^2+d^2}+\frac{4d^2}{\sqrt{x^2+d^2}}\ge 6d\), we get

$$\begin{aligned} h'(d)&= \frac{d}{\sqrt{x^2+d^2}} + \frac{4\sqrt{x^2+d^2} + \frac{4d^2}{\sqrt{x^2+d^2}}-6d}{4\sqrt{4y^2+4d\sqrt{x^2+d^2}-3d^2}} + \frac{d}{2\sqrt{4z^2+d^2}} - 1 \\ {}&\ge \frac{d}{\sqrt{(1\!-\!2\tau )^2+d^2}}\! +\! \frac{4\sqrt{(1\!-\!2\tau )^2 \!+\! d^2} \!+\! \frac{4d^2}{\sqrt{(1\!-\!2\tau )^2+d^2}} \!-\! 6d}{4\sqrt{16\tau ^2 \!+\! 4d\sqrt{(1\!-\!2\tau )^2 \!+\! d^2} \!-\! 3d^2}} \!+\! \frac{d}{2\sqrt{4\tau ^2 \!+\! d^2}}\! -\! 1. \end{aligned}$$

Let k(d) denote the function on the right hand side of the inequality above. As shown in the Appendix (inequality (A.1)), the function k(d) is positive for \(d \in \left[ 0,1\right] \). In particular, it follows that \(h'(d)\) is positive for all \(d \in \left[ 0,1\right] \), and hence h(d) is increasing. Thus \(h(d) > h(0) = x + y + z = 1\) for all \(d > 0\), which implies that \(f\left( d\sqrt{x^2+d^2} - d^2\right) > 1\). Hence \(a_{12} + a_{13} + a_{23} + d > 1\) whenever \(\delta \in \left[ 0, d\sqrt{x^2+d^2} - d^2\right] \). This concludes the proof in this case.

Case 2: \(\delta \in \left[ d\sqrt{x^2+d^2} - d^2, \frac{x^2-y^2}{2}\right] \). Let \(\ell (\delta )=\ell _{x,y,z,d}(\delta )\) denote the function given by

$$\begin{aligned} \ell \left( \delta \right) := \frac{\sqrt{d^2+4x^2-4\delta } + \sqrt{d^2+4y^2+4\delta } + \sqrt{d^2 + 4z^2}}{2} - \frac{d}{2}. \end{aligned}$$
(2.22)

Note that (2.17), (2.16) and (2.19) imply that we have \(a_{12} + a_{13} + a_{23} + d \ge \ell \left( \delta \right) \). The derivative of \(\ell \) is given by

$$\begin{aligned} \ell '(\delta ) = \frac{1}{\sqrt{d^2+4y^2+4\delta }} - \frac{1}{\sqrt{d^2 + 4x^2 - 4\delta }}. \end{aligned}$$

Since \(\delta \le \frac{x^2- y^2}{2}\), it follows that \(d^2 + 4x^2 - 4\delta \ge d^2 + 4y^2 + 4\delta \), and hence we have \(\ell '(\delta ) \ge 0\) for \(\delta \le \frac{x^2 - y^2}{2}\). Thus \(\ell (\delta )\) attains its minimum on our interval \(\left[ d\sqrt{x^2+d^2} - d^2, \frac{x^2-y^2}{2}\right] \) when \(\delta = d\sqrt{x^2+d^2} - d^2\). As the inequalities (2.18) and (2.19) give the same bound for \(a_{12}\) when \(\delta = d\sqrt{x^2+d^2} - d^2\), we conclude that \(\ell \left( d\sqrt{x^2+d^2} - d^2\right) \ge f\left( d\sqrt{x^2+d^2} - d^2\right) >1\) (the latter strict inequality being proved in our analysis of Case 1). Thus in this case also we must have \(a_{12} + a_{13} + a_{23} + d > 1\). Combined with Claim 2.13, our case analysis proves Lemma 2.12. \(\square \)

Now the conclusion Lemma 2.12 contradicts the fact that we have \(a_{12} + a_{13} + a_{23} + d = 1\); this contradiction shows no counterexample to Theorem 2.5 exists, concluding the proof of the theorem. \(\square \)

2.4 The \(\textbf{H}\)-Extremal Region: The Case \(\alpha _1\ge \alpha _2 +(1-\sqrt{\alpha _2})^2\)

Given a 3-colouring template \(\textbf{G}\) on N vertices with \(\vert G_1\vert \ge \max \left\{ \vert G_2 \vert , \vert G_3 \vert \right\} \), we define the function

$$\begin{aligned} g(\textbf{G}):= \vert G_1\vert + \vert G_2\vert + \vert G_3\vert -2\left( {\begin{array}{c}N\\ 2\end{array}}\right) - 2\max \left\{ \vert G_2\vert , \vert G_3\vert \right\} \\+ 2\sqrt{\left( {\begin{array}{c}N\\ 2\end{array}}\right) \max \left\{ \vert G_2\vert , \vert G_3\vert \right\} }. \end{aligned}$$

Theorem 2.15

There exists an absolute constant \(C>5\) such that the following hold: if \(\textbf{G}\) is a 3-colouring template on n vertices satisfying \(\vert G_1\vert \ge \vert G_2\vert \ge \vert G_3 \vert \) and

$$\begin{aligned} g(\textbf{G}) \ge Cn, \end{aligned}$$
(2.23)

then \(\textbf{G}\) contains a rainbow triangle.

Remark 2.16

Setting \(\vert G_i\vert =\alpha _i \frac{n^2}{2}\) for \(i\in [3]\) and assuming \(\alpha _3\le \alpha _2\), (2.23) implies after rearranging terms and dividing through by \(\frac{n^2}{2}\) that \(\alpha _3\ge 2-\alpha _1+\alpha _2-2\sqrt{\alpha _2}+\Omega (n^{-1})\), which up to the error term is exactly the bound we require in Theorem 1.13 part (b).

Proof

Let \(C>0\) be a sufficiently large constant to be specified later. It will be convenient to give a name to the function of \(\max \left\{ \vert G_2\vert , \vert G_3\vert \right\} \) involved in the definition of \(g(\textbf{G})\). Set therefore \(f_n: \ \mathbb {R}_{\ge 0}\rightarrow \mathbb {R}\) to be the function given by

$$\begin{aligned} f_n\left( x\right) :=x-\sqrt{x{n \atopwithdelims ()2}}. \end{aligned}$$

When n is clear from context, we often omit the subscript n and write f for the function \(f_n\). \(\square \)

Proposition 2.17

The function f is strictly decreasing in the interval \([0, \frac{1}{4}\left( {\begin{array}{c}n\\ 2\end{array}}\right) ]\) and strictly increasing in the interval \([\frac{1}{4} \left( {\begin{array}{c}n\\ 2\end{array}}\right) , \left( {\begin{array}{c}n\\ 2\end{array}}\right) ]\). Its unique minimum in \([0,\left( {\begin{array}{c}n\\ 2\end{array}}\right) ]\) is \(f(\frac{1}{4}\left( {\begin{array}{c}n\\ 2\end{array}}\right) )=-\frac{1}{4}\left( {\begin{array}{c}n\\ 2\end{array}}\right) \).

Proof

Simple calculus. \(\square \)

Suppose Theorem 2.15 is false, and let N be the least value of \(n\ge 3\) for which there exists a Gallai 3-colouring template satisfying the assumptions of Theorem 2.15. Among such Gallai colouring templates, let \(\textbf{G}\) be one maximising the size of the largest colour class \(\vert G_1\vert \). In the next lemma, we show that the sizes of the vertex set and of the colour classes in this putative counterexample to Theorem 2.15 cannot be too small.

Lemma 2.18

The following hold:

  1. (i)

    \(\sum _{i=1}^3 \vert G_i\vert >\frac{3}{2}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +CN\);

  2. (ii)

    \(N> 4C\);

  3. (iii)

    \(\vert G_2\vert > \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +\frac{C}{2}N\).

Proof

By Proposition 2.17 and (2.23), we have

$$\begin{aligned} \sum _{i=1}^3\vert G_i\vert&> 2\left( {\begin{array}{c}N\\ 2\end{array}}\right) +2f(\vert G_2\vert ) +CN\ge \frac{3}{2}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +CN, \end{aligned}$$

establishing (i). Further, by Theorem 1.3Footnote 4 we have \(\sum _i\vert G_i\vert \le 2\left( {\begin{array}{c}N\\ 2\end{array}}\right) \), which implies \(\frac{1}{2}\left( {\begin{array}{c}N\\ 2\end{array}}\right) > CN\) and thus \(N>4C\). This proves (ii). Finally, observe that (i) implies that

$$\begin{aligned} 2\vert G_2\vert \ge \vert G_2\vert +\vert G_3\vert \ge \sum _{i=1}^3 \vert G_i\vert -\left( {\begin{array}{c}N\\ 2\end{array}}\right) >\frac{1}{2}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +CN, \end{aligned}$$

and hence \(\vert G_2\vert > \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +\frac{CN}{2}\), proving (iii). \(\square \)

Next, we use the maximality of \(\vert G_1\vert \) and the minimality of N to prove two key structural lemmas about the colour classes of \(\textbf{G}\).

Lemma 2.19

\(G_{2}\cup G_3\subseteq G_{1}\).

Proof

We first show \(G_2\subseteq G_1\) using a simple idea from [18]. Consider the 3-colouring template \(\textbf{G}'\) with colour classes given by \(G'_1=G_1\cup G_2\), \(G'_2=G_1\cap G_2\) and \(G'_3=G_3\). It it easily checked that \(\textbf{G}'\) is also a Gallai colouring template, and that \(\sum _{i=1}^3\vert G'_i\vert =\sum _{i=1}^3 \vert G_i\vert \).

Our aim is to prove that \(\textbf{G}'\) also satisfies (2.23). By Lemma 2.18(i), we have

$$\begin{aligned} 2\max \left( \vert G'_2\vert , \vert G'_3\vert \right) \ge \sum _{i=1}^3 \vert G'_i\vert -\left( {\begin{array}{c}N\\ 2\end{array}}\right) =\sum _{i=1}^3 \vert G_i\vert -\left( {\begin{array}{c}N\\ 2\end{array}}\right) >\frac{1}{2}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +CN, \end{aligned}$$

whence \(g'_2:= \max \left( \vert G'_2\vert , \vert G'_3\vert \right) \) satisfies \(g'_2\ge \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +\frac{C}{2}N\). Clearly \(g'_2\le \vert G_2\vert \), whence \(f(g'_2)\le f(\vert G_2\vert )\) by Proposition 2.17. We thus have

$$\begin{aligned} \sum _{i=1}^3 \vert G'_i\vert =\sum _{i=1}^3 \vert G_i\vert > 2\left( {\begin{array}{c}N\\ 2\end{array}}\right) +2 f(\vert G_2\vert ) +CN\ge 2\left( {\begin{array}{c}N\\ 2\end{array}}\right) +2 f(g'_2) +CN, \end{aligned}$$

so that (after swapping colours 2 and 3 if necessary) \(\textbf{G}'\) is also a Gallai template on N vertices satisfying the assumptions of Theorem 2.15. Since \(\textbf{G}\) was chosen to maximise the size of the first colour class among such counterexamples to Theorem 2.15, we have that \(\vert G_1\vert \ge \vert G'_1\vert =\vert G_1\cup G_2\vert \). Thus \(G_2\subseteq G_1\), as claimed.

That \(G_3\subseteq G_1\) is proved by using a similar, albeit simpler argument (since now both sides of (2.23) are unchanged when we replace \(G_1\) and \(G_3\) by \(G_1\cup G_3\) and \(G_1\cap G_3\) respectively). \(\square \)

Lemma 2.20

There are no rainbow edges in \(\textbf{G}\): \(G_{1}\cap G_2\cap G_3=\emptyset \).

Proof

Suppose for a contradiction that \(xx' \in G_1\cap G_2\cap G_3\). We shall show the subtemplate \(\textbf{G}'\) induced by \(V\setminus \{x,x'\}\) is a smaller counterexample to Theorem 2.15.

Observe that for every \(y\in V\setminus \{x,x'\}\), if one of the edges \(xy, x'y\) is bi-chromatic or rainbow, then the other edge must be missing from \(\bigcup _{i=1}^3 G_i\) (as otherwise we have a rainbow triangle in \(\textbf{G}\)). In particular, writing R for the number of rainbow edges from \(xx'\) to \(V{\setminus } \{x,x'\}\) (which by our observation satisfies \(R\le N-2\)), we have

$$\begin{aligned} \sum _{i=1}^3 \vert G'_i\vert \! \ge \! \sum _{i=1}^3 \vert G_i\vert \!-\! 2(N-2)-3-R&> 2\left( {\begin{array}{c}N\\ 2\end{array}}\right) \!+\!2f_N(\vert G_2 \vert ) \!+\!CN\!-\! 2N-R+1\nonumber \\&= 2\left( {\begin{array}{c}N-2\\ 2\end{array}}\right) +C(N-2) \nonumber \\&\quad +2f_N (\vert G_2\vert ) + 2N-R +2C-5 \end{aligned}$$
(2.24)

Clearly, the size of the second largest colour class in \(\textbf{G}'\) is at most \(\vert G_2\vert -R-1\) (since both \(\vert G_2\vert \) and \(\vert G_3\vert \) decreased by at least \(R+1\) when we removed the rainbow edge \(xx'\) and the R rainbow edges from \(xx'\) to \(V\setminus \{x,x'\}\)). Now, we have that

$$\begin{aligned}&-R+ 2f_{N}(\vert G_2\vert )-2f_{N-2}(\vert G_2\vert -R-1)\nonumber \\&\quad = R+2-2\sqrt{\left( {\begin{array}{c}N\\ 2\end{array}}\right) \vert G_2\vert }\left( 1- \sqrt{\frac{N^2-5N+6}{N^2-N}}\sqrt{1 -\frac{R+1}{\vert G_2\vert }} \right) . \end{aligned}$$
(2.25)

Write \(\vert G_2\vert =\alpha _2 \left( {\begin{array}{c}N\\ 2\end{array}}\right) \) and \(R+1=\rho (N-1)\). By Lemma 2.18(iii), we know \(\alpha _2 \in [\frac{1}{4},1]\). Further, by our observation above \(R+1\le N-1\), whence \(\rho \le 1\). By a straightforward asymptotic analysis,

$$\begin{aligned}&1 + \rho (n-1) -2\left( {\begin{array}{c}n\\ 2\end{array}}\right) \sqrt{\alpha _2}\left( 1- \sqrt{\frac{1-5n^{-1}+6n^{-2}}{1-n^{-1}}} \sqrt{1-\frac{2\rho }{\alpha _2 n}} \right) \nonumber \\&\quad =\left( \rho -2\sqrt{\alpha _2}-\frac{\rho }{\sqrt{\alpha _2}}\right) n +O(1). \end{aligned}$$
(2.26)

For \(\alpha _2\in [1/4, 1]\), and \(\rho \in [0,1]\), we have \(\rho - \frac{\rho }{\sqrt{\alpha _2}} \ge 1 - \frac{1}{\sqrt{\alpha _2}}\). Since \(\left( 1 - \sqrt{\alpha _2}\right) \left( \sqrt{\alpha _2} - \frac{1}{2}\right) \ge 0\), it follows that \(1 - 2\sqrt{\alpha _2} - \frac{1}{\sqrt{\alpha _2}} \ge -2\). Combining this fact with (2.24), (2.25) and (2.26), and picking \(C>5\) sufficiently large to ensure that we can absorb the O(1) term in (2.26) with the \(2C-5\) term in (2.24) (recall that \(N>4C\) by Lemma 2.18(ii), so picking C sufficiently large ensures N itself can be made sufficiently large), we get

$$\begin{aligned} \sum _{i=1}^3 \vert G'_i\vert&> 2\left( {\begin{array}{c}N-2\\ 2\end{array}}\right) +2f_{N-2}(\vert G_2\vert -R-1) +C(N-2). \end{aligned}$$

We are now done once we observe that if \(g'_2\) is the size of the second largest colour class in \(\textbf{G}'\), then \(f_{N-2}(g'_2)\le f_{N-2}(\vert G_2\vert -R-1)\). Indeed, as we noted above, \(g'_2\le \vert G_2\vert - R-1\). On the other hand, note that all colour classes have lost at most \(1+ 2(N-2)=2N-3\) edges when we removed \(xx'\) from V. Thus by Lemma 2.18(iii)

$$\begin{aligned} g'_2\ge \vert G_2\vert - 2N+3 \ge \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +\frac{C}{2}N -2N+3>\frac{1}{4}\left( {\begin{array}{c}N-2\\ 2\end{array}}\right) . \end{aligned}$$

As \(f_{N-2}\) is increasing for \(x\ge \frac{1}{4}\left( {\begin{array}{c}N-2\\ 2\end{array}}\right) \) (Proposition 2.17), this last inequality implies \(f_{N-2}(g'_2)\le f_{N-2}(\vert G_2\vert -R-1)\). Thus \(\textbf{G}'\) is indeed a counterexample to Theorem 2.15, contradicting the vertex minimality of \(\textbf{G}\). \(\square \)

Corollary 2.21

There are no bi-chromatic edges in colours 23: \(G_2\cap G_3=\emptyset \).

Proof

Since there are no rainbow edges (Lemma 2.20), this is immediate from the fact proved in Lemma 2.19 that \(G_2\cap G_3\subseteq G_1\). \(\square \)

We now consider a largest matching of bi-chromatic edges from \(\textbf{G}\). By Lemmas 2.19 and 2.20, this matching M is the disjoint union of two matchings \(M_{12}\) and \(M_{13}\) of bi-chromatic edges in colours 12 and 13 respectively. Let \(V_{12}\) and \(V_{13}\) denote the collections of vertices contained in some edge of \(M_{12}\) and \(M_{13}\) respectively, and let \(D:=V\setminus (V_{12}\sqcup V_{13})\).

We shall perform modifications of \(\textbf{G}\) in a sequential manner, to obtain a new colouring template \(\textbf{G}''\), which may contain some rainbow triangles, but is well-structured with respect to the partition \(V=V_{12}\sqcup V_{13} \sqcup D\) while still satisfying a slightly weaker form of (2.23). This will lead to the desired contradiction (Lemma 2.25).

Before we start modifying our colouring template, we shall make some observations about \(\textbf{G}\), introduce an auxiliary graph A on M, and observe some elementary properties of g, our function of colouring templates, all of which we shall need to analyse our sequence of modifications of \(\textbf{G}\).

Proposition 2.22

For \(j \in \{2,3\}\), set \(\{k\}:=\{2,3\}\setminus \{j\}\). Then the following hold:

  1. (i)

    for any pair of distinct edges \(X,X'\in M_{1j}\), if there is any edge in colour k from X to \(X'\), we have that at least two edges from X to \(X'\) are missing from \(G_1\cup G_2\);

  2. (ii)

    for any edge \(X\in M_{1j}\) and any edge \(Y\in M_{1k}\), we have \(\sum _{i=1}^3 \vert G_i[X, Y]\vert \le 5\), with equality only attained if \(\vert G_2[X, Y]\vert =\vert G_{3}[X,Y]\vert =1\) and \(\vert G_1[X,Y]\vert =3\);

  3. (iii)

    if \(X\in M_{1j}\) and \(Y, Y'\) are distinct edges in \(M_{1k}\) such that \(\sum _{i=1}^3 \vert G_i[X, Y]\vert = \sum _{i=1}^3 \vert G_i[X, Y']\vert =5\), then \(\vert G_k[Y,Y']\vert \le 3\);

  4. (iv)

    if \(v\in D\) and \(X\in M_{1j}\) are such that there exists a bi-chromatic edge in colour 1k from v to X, then \(\sum _{i=1}^3 \vert G_i[X,v] \vert =2\);

  5. (v)

    there is no bi-chromatic edge in D (and in particular D is an independent set in \(G_2\cup G_3\));

  6. (vi)

    for every \(X\in M_{ij}\), there exists at most one \(v\in D\) sending bi-chromatic edges to both endpoints of X.

Proof

Parts (i)–(iv) are immediate from the fact \(\textbf{G}\) is rainbow \(K_3\)-free and simple case analysis. Parts (v)–(vi) follow from the maximality of the bi-chromatic matching M and the fact that \(G_2\cup G_3\subseteq G_1\). \(\square \)

Next, we define an auxiliary graph A on the edges of the matching \(M_{12}\sqcup M_{13}\) by including a pair \(X,X' \in M_{1j}\) in A if \(\vert G_j[X, X']\vert \le 3\) and a pair \(X\in M_{12}\), \(Y\in M_{13}\) if \(\sum _{i=1}^3 \vert G_i[X, Y]\vert = 5\). Finally, we make some elementary observations about g.

Proposition 2.23

Let \(\textbf{G}'\) be a 3-colouring template with \(\vert G'_1\vert \ge \max \left\{ \vert G'_2\vert , \vert G'_3\vert \right\} \). If \(\max \left\{ \vert G'_2\vert , \vert G'_3\vert \right\} \le \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), then \(g(\textbf{G}')\le 2N\).

Proof

Since \(\vert G_1\vert \le \left( {\begin{array}{c}N\\ 2\end{array}}\right) \), our assumption together with the bound \(\sqrt{1+2x}\le 1+x\) gives

$$\begin{aligned} g(\textbf{G}')\le -\left( {\begin{array}{c}N\\ 2\end{array}}\right) + \left( {\begin{array}{c}N\\ 2\end{array}}\right) \sqrt{1+\frac{8}{N-1}} \le 2N. \end{aligned}$$

\(\square \)

Proposition 2.24

Suppose \(\max \left( \vert G'_2\vert , \vert G'_3\vert \right) \ge \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\). Then the following hold:

  1. (i)

    the value of \(g(\textbf{G}')\) does not decrease if we delete a bi-chromatic edge and add two edges in colour 1;

  2. (ii)

    for \(t\le N\), the value of \(g(\textbf{G}')\) decreases by at most t if we delete up to t edges in colours 2 or 3.

Proof

For part (i), assume without loss of generality that \(\vert G'_2\vert \ge \vert G'_3\vert \). Replacing a bi-chromatic edge in colour 13 by two edges in colour 1 does not change the value of g. If \(\vert G'_3\vert = \vert G'_2\vert \), then similarly we do not change the value of g by removing a bi-chromatic edge in colours 12 and adding in two edges in colour 1. On the other other hand, if \(\vert G'_3\vert < \vert G'_2\vert \), then deleting a bi-chromatic edge in colours 12 and adding in two edges in colour 1 keeps \(\sum _{i=1}^3 \vert G'_i\vert \) constant and strictly decreases \(2f(\vert G'_2\vert )= 2\vert G'_2\vert -2\sqrt{\left( {\begin{array}{c}N\\ 2\end{array}}\right) \vert G'_2\vert }\) (since \(f=f_N(x)\) is increasing in the interval \([\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) , \left( {\begin{array}{c}N\\ 2\end{array}}\right) ]\), as shown in Proposition 2.17); thus \(g(\textbf{G}')=\sum _{i=1}^3\vert G'_i\vert -2f(\max (\vert G'_2\vert , \vert G'_3\vert ))\) actually increases in this case.

The proof of part (ii) follows similarly, and is left as an exercise to the reader. \(\square \)

We are now ready to embark upon our sequence of modifications of \(\textbf{G}\). Set \(\textbf{G}'=\textbf{G}\). Recall that initially \(\vert G'_2\vert \ge \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +\frac{C}{2}N>\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +2N\) by Proposition 2.18. Also, initially \(\textbf{G}'\) has the two properties that it contains no rainbow edge and that it satisfies \(G'_2\sqcup G'_3\subseteq G'_1\), both of which will be preserved by our modifications. Note however that our modifications will not preserve the property of being rainbow \(K_3\)-free. Also, if the value of \(\max \{\vert G_2'\vert , \vert G_3'\vert \}\) ever becomes too small by dropping below \(\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), we shall immediately stop the modification process.

Step 1: dealing with D. We go through the edges of the matching \(M_{12}\). For each such edge X, we go through the vertices of D. If \(v\in D\) sends a bi-chromatic edge of colours 13, then by Proposition 2.22(iv), we can replace this bi-chromatic edge by two edges in colour 1 from v to X. By Proposition 2.24(i), this does not decrease the value of g. If this change brings \(\max (\vert G'_2\vert , \vert G'_3\vert )\) below \(\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), then we stop our procedure and output the colouring template \(\textbf{G}''=\textbf{G}'\).

We then repeat the same procedure with colours 2 and 3 switching roles, i.e. replace bi-chromatic edges in colours 12 from D to edges of \(M_{13}\) by pairs of edges in colour 1 (and outputting \(\textbf{G}''=\textbf{G}'\) if the size of the second largest colour class ever becomes too small). Throughout, the value of \(g(\textbf{G}')\) does not decreases.

Next, we sequentially go through the edges \(M_{12}\cup M_{13}\). By Proposition 2.22(vi), for each such edge \(X\in M_{1j}\), there is at most one vertex \(v_X\in D\) such that \(v_X\) sends two bi-chromatic edges in colours 1j to X. If such a vertex \(v_X\) exists, then we delete one of the two edges in colour j from \(v_X\) to X.

If the size of the second largest colour class in \(\textbf{G}'\) does not become too small, then at the end of this sequence of operations we have deleted at most \(N/2<N\) edges in colours 2 and 3, and so by Proposition 2.24(ii) we have \(g(\textbf{G}')\ge g(\textbf{G})-N\) by the end of this step. Further, \(\textbf{G}'\) now has the property that for \(j\in \{2,3\}\) at most half of the edges from \(M_{1j}\) to D are bi-chromatic in colours 1j, and the rest of those edges are in colour 1 or absent from \(\bigcup _{i=1}^3G'_i\).

Step 2: cleaning inside the \(V_{1j}\). We sequentially go through the pairs of distinct edges \(X,X' \in M_{12}\). For each such pair, if there is one edge in colour 3 between X and \(X'\) then we have that (a) \(XX'\) is an edge in our our auxiliary graph A, and (b) there are at least two edges from X to \(X'\) which are missing in \(G_1\cup G_2\) (by Proposition 2.22(i)). We then delete this edge in colour 3, and arbitrarily add in one of the at least two missing edges in colour 1 between X and \(X'\). If there are two edges in colour 3 between X and \(X'\), then we replace them with the two missing edges from \(G_1[X, X']\), one after the other. By Proposition 2.24, this does not decrease the value of \(g(\textbf{G}')\). Note that there cannot be more than 2 edges in colour 3 between them as \(G_3 \subseteq G_1\). If one of our changes brings \(\max (\vert G'_2\vert , \vert G'_3\vert )\) below \(\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), then we stop our procedure and output the colouring template \(\textbf{G}''=\textbf{G}'\).

We then repeat the same procedure with colours 2 and 3 switching roles, i.e. replace edges in colours 2 inside \(V_{13}\) by edges in colour 1 (and outputting \(\textbf{G}''=\textbf{G}'\) if the size of the second largest colour class ever becomes too small). Throughout, the value of \(g(\textbf{G}')\) does not decrease (and thus remains at least \(g(\textbf{G})-N\)). If the size of the second largest colour class in \(\textbf{G}'\) does not become too small in the process, then when we are done with this sequence of operations we have that for \(j\in \{2,3\}\) the set \(V_{1j}\) only contains edges in colours 1 or j and for every edge \(XX'\in A[V_{1j}]\), there is (still) at least one edge in \((X, X')^{(2)}\) missing in \(G'_j\).

Step 3: cleaning across \(V_{12}\times V_{13}\). Recall the auxiliary graph A introduced after Proposition 2.22. We sequentially go through the pairs \(X\in M_{12}\), \(Y\in M_{13}\) with \(XY\notin A\). For each such pair, we have \(\sum _{i=1}^4G_i[X,Y]\le 4\). So we can sequentially delete edges from X to Y in colours 2 or 3, and replace them by edges from X to Y in colour 1. If this change brings \(\max (\vert G'_2\vert , \vert G'_3\vert )\) below \(\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), then we stop our procedure and output the colouring template \(\textbf{G}''=\textbf{G}'\). By Proposition 2.24(i), this does not decrease the value of \(g(\textbf{G}')\).

Next, we turn our attention to the pairs \(X\in M_{12}\), \(Y\in M_{13}\) with \(XY\in A\). It follows from Proposition 2.22(iii) that for each \(X\in M_{12}\), the collection of \(Y\in M_{13}\) with \(XY\in A\) forms a clique in A. By a graph theoretic result of Aharoni et al. [1, Lemma 2.2], under such a condition on the neighbourhoods we have

$$\begin{aligned} \vert A[M_{12},M_{13}]\vert \le \vert A[M_{12}] \vert + \vert A[M_{13}] \vert + \frac{\vert M_{12}\vert + \vert M_{13} \vert }{2} \end{aligned}$$

For convenience, set \(e_{12} = \vert A[M_{12}] \vert \), \(e_{13} = \vert A[M_{13}] \vert \) and \(e = \vert A[M_{12},M_{13}] \vert \). We begin by moving \(\min \{e_{12},e\}\) edges from \(G_2[M_{12}, M_{13}]\) to \(G_2[M_{12}]\) and \(\min \{e_{13},e\}\) edges from \(G_3[M_{12}, M_{13}]\) to \(G_3[M_{13}]\) (adding edges in colour 1 to preserve \(G'_2\sqcup G'_3\subseteq G'_1\) if necessary). This clearly does not decrease the value of g. Next we go through the remaining edges in colours 2 or 3 in \((M_{12},M_{13})^{(2)}\) one after the other, and replace all but at most \(e -\min (e,e_{12})-\min (e,e_{13})\le \frac{\vert M_{12} \vert + \vert M_{13} \vert }{2}\) of them by edges in colour 1.

To be more precise, at each step of this subprocess we let \(j\in \{2,3\}\) be the second largest colour class in \(\textbf{G}'\) and k the third largest colour class. If there is in \((M_{12},M_{13})^{(2)}\) any edge f of \(G_j\) and at least one missing edge in \(G_1\), then we remove the edge f in colour j from \(\textbf{G}'\) and replace it by an edge \(f'\) in colour 1; if this brings \(\max (\vert G'_2\vert , \vert G'_3\vert )\) below \(\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), then we stop our procedure and output the colouring template \(\textbf{G}''=\textbf{G}'\). Otherwise if there is in \((M_{12},M_{13})^{(2)}\) any edge f of \(G_k\) and any edge \(f'\) missing from \(G_1\), then we remove the edge f in colour k from \(\textbf{G}'\) and replace it by an edge in colour 1. By Proposition 2.24(i) this does not decrease g.

When the subprocess ends, we have at most \(\frac{\vert M_{12}\vert + \vert M_{13} \vert }{2}\le N/4\) edges in colours 2 or 3 left between X and Y, which we remove. By Proposition 2.24(ii), deleting these edges reduces the value of g by at most \(\frac{N}{4}\). If this brings \(\max (\vert G'_2\vert , \vert G'_3\vert )\) below \(\frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), then we stop our procedure and output the colouring template \(\textbf{G}''=\textbf{G}'\). Otherwise, we have decreased the value of g by at most N/4 in total in this step, whence \(g(\textbf{G}')\ge g(\textbf{G})-2N\), and \(\textbf{G}'\) has the following property for \(j\in \{2,3\}\):

$$\begin{aligned}&\text {at most half of the edges from }V_{1j}\text { to }D\text { are in } G'_j,\text { and all other edges of }G'_j\nonumber \\ {}&\quad \text { lie inside }V_{1j}. \end{aligned}$$
(2.27)

We set \(\textbf{G}''=\textbf{G}'\) and terminate our modification procedure. We are now ready to bound \(g(\textbf{G}'')\) and obtain the desired contradiction.

Lemma 2.25

\(g(\textbf{G}'')\le 3N\).

Proof

If \(\vert G''_2\vert \le \frac{1}{4}\left( {\begin{array}{c}N\\ 2\end{array}}\right) +N\), then our claim is immediate from Proposition 2.23. Otherwise, set \(x_{1j}N:=\vert V_{1j} \vert \) for \(j\in \{2,3\}\) and \(dN:=\vert D\vert \). By (2.27), we have \(\vert G''_j \vert \le \left( {\begin{array}{c}x_{1j}N\\ 2\end{array}}\right) +\frac{1}{2}x_{1j}dN^2\). Clearly \(\vert G''_1\vert \le \left( {\begin{array}{c}N\\ 2\end{array}}\right) \). Assume without loss of generality that \(\vert G''_2\vert \ge \vert G''_3\vert \).

Now, the function \(x\mapsto -x+2\sqrt{x\left( {\begin{array}{c}N\\ 2\end{array}}\right) }\) is increasing in the interval \([0, \left( {\begin{array}{c}N\\ 2\end{array}}\right) ]\). It then follows from the bounds on the sizes of the colour classes above that, for a choice of the constant \(C>0\) sufficiently large, we have

$$\begin{aligned} g(\textbf{G}'')&= \vert G''_1\vert -2\left( {\begin{array}{c}N\\ 2\end{array}}\right) + \vert G''_3\vert -\vert G''_2\vert +2\sqrt{\vert G''_2\vert \left( {\begin{array}{c}N\\ 2\end{array}}\right) }\\&\le -\left( {\begin{array}{c}N\\ 2\end{array}}\right) + \left( \left( {\begin{array}{c}x_{13}N\\ 2\end{array}}\right) +\frac{x_{13}dN^2}{2}\right) -\left( \left( {\begin{array}{c}x_{12}N\\ 2\end{array}}\right) +\frac{x_{12}dN^2}{2}\right) \\&\quad +2\sqrt{\left( \left( {\begin{array}{c}x_{12}N\\ 2\end{array}}\right) +\frac{x_{12}dN^2}{2}\right) \left( {\begin{array}{c}N\\ 2\end{array}}\right) }\\&<\frac{N^2}{2}\Bigg (-1+(1-d-x_{12})^2 -(x_{12})^2 +(1-2x_{12}-d)d \\ {}&\quad +2\sqrt{x_{12}(x_{12}+d)}\Bigg ) + 3N\\&=N^2\left( -d-2x_{12}+2\sqrt{x_{12}(x_{12}+d)}\right) + 3N \le 3N. \end{aligned}$$

\(\square \)

Since, as noted at the end of our modification procedure, \(g(\textbf{G})\le g( \textbf{G}'')+2N\), it follows from Lemma 2.25 that \(g(\textbf{G})\le 5N\), whence \(\textbf{G}\) fails to satisfy (2.23) (since C was chosen so that \(C>5\)), a contradiction. Thus there is no counterexample to Theorem 2.15, concluding our proof.\(\square \)

2.5 Putting It Together: Proof of Theorem 1.13 and Corollary 1.16

Proof of Theorem 1.13

For part (a), the statement (i) follows from the definition of \(\mathcal {R}'_1\): \(\alpha _2=x^2+(1-x-y)^2\ge 1-x^2=\alpha _3\). The statement (ii) follows directly from Theorem 2.5, while the statement (iii) follows from Proposition 2.1. Similarly for part (b), the statement (i) follows from the definition of \(\mathcal {R}_2\): \(\alpha _3=2-\alpha _1-2\sqrt{\alpha _2}+\alpha _2\), which is at most \(\alpha _2\) since \(\alpha _1\ge 2-2\sqrt{\alpha _2}\). The statements (ii) and (iii) then follow from Theorem 2.15 and Proposition 2.1.

Thus the only task that remains is to establish part (c). Our goal is to show that if \(\alpha _1\ge \alpha _2\) and \((\alpha _1, \alpha _2)\notin \mathcal {R}'_1\cup \mathcal {R}_2\), then \((\alpha _1, \alpha _2, \alpha _2)\) is not a forcing triple. By Propositions 2.2(a)–(d), we see that if \(\alpha _1<\frac{1+\tau ^2}{2}\), \(\alpha _2<\frac{1}{4}\), \(\alpha _1+\alpha _2<1\) or \((\alpha _1, \alpha _2)\in \mathcal {R}_1{\setminus } \mathcal {R}'_1\), then we are done. The only region this leaves uncovered consists of the \((\alpha _1, \alpha _2)\) with \(\alpha _2\in [\frac{1}{4}, \frac{1}{2})\) and \(\max \left\{ 1-\alpha _2, 1-2\sqrt{\alpha _2}+2\alpha _2\right\} \le \alpha _1<2-2\sqrt{\alpha _2}\). Consider any \(\alpha _2\in [\frac{1}{4}, \frac{1}{2})\). Then for any \(\alpha _1< 2-2\sqrt{\alpha _2}\), there exists \(\varepsilon >0\) such that \(\alpha _1<2-2\sqrt{\alpha _2 + \varepsilon }-\varepsilon \) and \(\alpha _2 + \varepsilon < \frac{1}{2}\). Setting \(a=\lfloor \sqrt{(\alpha _2+\varepsilon ) n}\rfloor \), \(b=\lfloor \frac{2\sqrt{(\alpha _2+\varepsilon )}-1}{2\sqrt{(\alpha _2+\varepsilon )}}n\rfloor \) and \(c=n-a-b\), we have (by Proposition 2.1 or a quick calculation) that the n-vertex Gallai 3-colouring template \(\textbf{H}(a,b,c)\) has colour density

$$\begin{aligned} \left( 2-2\sqrt{\alpha _2+\varepsilon }, \alpha _2+\varepsilon , \alpha _2+\varepsilon \right) +\left( O(n^{-1}), O(n^{-1}), O(n^{-1})\right) , \end{aligned}$$

from which it follows that \((\alpha _1, \alpha _2, \alpha _2)\) is not a forcing triple (since \(\alpha _1+\varepsilon <2-2\sqrt{\alpha _2+\varepsilon }\)). \(\square \)

Proof of Corollary 1.16

We need to show that in any Gallai n-vertex 3-colouring template with colour density vector \((\alpha _1, \alpha _2, \alpha _3)\) and \(\alpha _1\ge \alpha _2\ge \alpha _3\), \(\prod _{i=1}^3\alpha _i\le h(\upsilon )+o(1)\). By Theorem 1.13, it suffices to show this for \((\alpha _1, \alpha _2)\in \mathcal {R}'_1\cup \mathcal {R}_2\).

If \((\alpha _1, \alpha _2)\in \mathcal {R}_2\), then by Theorem 1.13(b)(ii)–(iii), it is enough to show that for any choice of \(x,y\ge 0\) with \(1-x-y\ge 0\), the Gallai 3-colouring template \(\textbf{H}(\lfloor xn\rfloor ,\lfloor yn\rfloor ,n-\lfloor x n\rfloor -\lfloor yn\rfloor )\) satisfies \(\prod _{i=1}^3 \vert H_i \vert \le h(\upsilon )\left( {\begin{array}{c}n\\ 2\end{array}}\right) ^3+O(n^5)\). Now, by Proposition 2.1, \(\prod _{i=1}^3 \vert H_i \vert = f_H(x,y)\left( {\begin{array}{c}n\\ 2\end{array}}\right) ^3 +O(n^5)\), where \(f_H(x,y)\) is given by

$$\begin{aligned} f_H(x,y):= (1-2xy)x^2 ((1-x)^2+2xy). \end{aligned}$$

For x fixed and \(y\in [0, 1-x]\), simple calculus tells us that

$$\begin{aligned} f_H(x,y)\le \left\{ \begin{array}{ll} f_H(x, \frac{2-x}{4}) &{} \text {if }x\le \frac{2}{3}\\ f_H(x, 1-x) &{} \text {if }x>\frac{2}{3}.\end{array}\right. \end{aligned}$$

Now it can be checked that \(f_H(x, \frac{2-x}{4})\) is an increasing function of x in the interval \([0, \frac{2}{3}]\) (its derivative with respect to x is \(\frac{x}{2}\left( (1-x)^2+1\right) \left( 3(x-\frac{2}{3})^2+\frac{2}{3}\right) \ge 0\)), whence for any such x we have \(f_H(x, \frac{2-x}{4})\le f_H(\frac{2}{3}, \frac{1}{3})\). It follows that for any choice of \(x,y\ge 0\) with \(x+y \le 1\), we have \(f_H(x,y)\le \max _{x'\in [0,1]}f_H(x',1-x')= \max _{x'\in [0,1]}\left( (x')^2+(1-x')^2\right) (x')^2\left( 1-(x')^2\right) = h(\upsilon )\) as required.

Similarly if \((\alpha _1, \alpha _2)\in \mathcal {R}'_1\), then by Theorem 1.13(a)(ii)–(iii), it is enough to show that for any choice of \(x\ge \frac{1}{2}\) and \(y\ge \frac{1-x}{2}\) with \(1-x-y\ge 0\), the Gallai 3-colouring template \(\textbf{F}(\lfloor xn\rfloor ,\lfloor yn\rfloor ,n-\lfloor x n\rfloor -\lfloor yn\rfloor )\) satisfies \(\prod _{i=1}^3 \vert F_i \vert \le h(\upsilon )\left( {\begin{array}{c}n\\ 2\end{array}}\right) ^3+O(n^5)\). By Proposition 2.1 we have \(\prod _{i=1}^3 \vert F_i\vert = f_F(x,y)\left( {\begin{array}{c}n\\ 2\end{array}}\right) ^3+O(n^5)\), where \(f_F(x,y):=(x^2+y^2)\left( x^2+(1-x-y)^2\right) (1-x^2)\). Now

$$\begin{aligned}\frac{\partial f_F}{\partial y}(x,y)= 4(1-x^2)\left( y-\frac{1-x}{2}\right) \left( x^2+y^2- (1-x)y\right) ,\end{aligned}$$

and for \(y\ge \frac{1-x}{2}\) we have \(x^2+y^2-(1-x)y \ge x^2+\left( \frac{1-x}{2}\right) ^2 -2\left( \frac{1-x}{2}\right) ^2= \frac{1}{4}(3x-1)(x+1)\ge 0\) for all \(x\ge \frac{1}{2}\). Thus \(\frac{\partial f_F}{\partial y}(x,y)\ge 0\) for (xy) in the domain we are considering, and \(f_F(x,y)\le f_F(x,1-x)= \left( x^2+(1-x)^2\right) x^2\left( 1-x^2\right) \le h(\upsilon )\), as required.\(\square \)