Paths of Length Three are $K_{r+1}$-Tur\'an Good

The generalized Tur\'an problem $ext(n,T,F)$ is to determine the maximal number of copies of a graph $T$ that can exist in an $F$-free graph on $n$ vertices. Recently, Gerbner and Palmer noted that the solution to the generalized Tur\'an problem is often the original Tur\'an graph. They gave the name"$F$-Tur\'an-good"to graphs $T$ for which, for large enough $n$, the solution to the generalized Tur\'an problem is realized by a Tur\'an graph. They prove that the path graph on two edges, $P_2$, is $K_{r+1}$-Tur\'an-good for all $r \ge 3$, but they conjecture that the same result should hold for all $P_\ell$. In this paper, using arguments based in flag algebras, we prove that the path on three edges, $P_3$, is also $K_{r+1}$-Tur\'an-good for all $r \ge 3$.


Introduction
One of extremal graph theory's most celebrated results was introduced in [26] by Turán who asked how many edges a (simple) graph on n vertices can contain if it has no clique containing r + 1 vertices. Turán's solution, which we denote ex(n, K r+1 ), is asymptotically (1 − 1 r ) n 2 . Additionally, Turán showed that the unique extremal graph is the complete r-partite graph on n vertices with parts of size n r or n r (so that no pair of parts differs in size by more than one). We call this graph the Turán graph and denote it T r (n).
The first extensions to Turán's theorem considered forbidding graphs other than cliques. For any graph F , we say a graph G is F -free if it contains no (not necessarily induced) subgraph isomorphic to F . We use ex(n, F ) to denote the maximal number of edges in an F -free graph on n vertices. The general case is solved asymptotically by the Erdős-Stone-Simonovits Theorem [9] which proves ex(n, F ) = 1 − 1 To further generalize the problem, one may consider counting subgraphs other than edges. Let ν(T, G) denote the number of distinct, not necessarily induced subgraphs of G isomorphic to T . We denote by ex(n, T, F ) the maximum of ν(T, G) over all F -free graphs G on n vertices. (Here T is the "target" graph while F is "forbidden.") The first question of this form to be resolved was due to Zykov in 1949 [27] who determined the value of the function ex(n, K t , K r ) when t < r by proving that the Turán graph is the unique extremal graph.
Theorem 1.1 (Zykov [27]). Let r and t be integers such that t < r. Then for all n, the Turán graph T t (n) is the unique K r -free graph on n vertices containing the maximum number of K t subgraphs.
Several sporadic cases were investigated (see, for example, [6,15]) before 2015 when Alon and Shikhelman introduced a systematic study in [2] in which they determine, among other results, that for forbidden graphs F with χ(F ) = k + 1 > r, ex(n, K r , F ) = (1 + o(1)) k r n k r .
A more precise result can be found in [22]. Since then, the area has been widely studied; see [8,11,16,20,21] for an (incomplete) sampling of authors and results. As in the original Zykov result, for many choices of T and F the Turán graph emerges as the optimal graph, at least for large enough n. In [12], Gerbner and Palmer introduced the term F -Turán-good to describe such target graphs T : Definition 1.2. Fix an (r + 1)-chromatic graph F and a graph T that does not contain F as a subgraph. We say that T is F -Turán-good if ex(n, T, F ) = ν(T, T r (n)) for every n large enough.
In the same paper, Gerbner and Palmer prove that the path graph on edges, P , is K r+1 -Turán-good for = 2 and r ≥ 3. They conjecture that paths should be Turán-good for all choices of r and . In this paper we establish that P 3 , the path on three edges, is K r+1 -Turán-good for all r ≥ 3.
To be precise, define the density of H in G to be d(H, G) = ν(H, G) |G| |H| −1 and let F n,r be the family of K r+1 -free graphs on n vertices. We define OPT r (P 3 ) = lim n→∞ max Gn∈Fn,r d(P 3 , G n ).
Then the following theorem is the primary result of this paper: (ii) If n is sufficiently large, then P 3 is K r+1 -Turán good.
Note that in [12], Gerbner and Palmer provided a proof of part (i) of Theorem 1.3. Part (ii) is an entirely new result. We will re-prove part (i) in the language of flag algebras, since we will require this proof to obtain part (ii).
In [11], Gerbner and Palmer proved that for two graphs T and F , where χ(F ) = r, Combined with Theorem 1.3, their theorem implies the following corollary.
Corollary 1.4. For any graph F with chromatic number r ≥ 3, In the remainder of this section, we establish the conventions used thorough the paper, reference a few well-known results that will be of use throughout the proof, and then provide a brief introduction to the flag algebra method. Section 2 contains the flag algebra calculations we use to establish part (i) of Theorem 1.3. In Section 3 we establish a stability result, proving that near-extremal graphs have small edit distance from the Turán graph. Then in Section 4 we use that stability argument to show that the Turán graph is optimal for large enough n. We conclude in Section 5 with some thoughts on what this result means for Gerbner and Palmer's conjecture for general paths P .

Background and Conventions
We use P to denote the path graph with edges and + 1 vertices. If a copy of P 3 in G is defined by the edges wx, xy and yz, then we will use wxyz to denote it. Note that a set of four vertices in G will frequently give multiple distinct copies of P 3 . We use wxyz for that specific ordering. We will need the following corollary of Theorem 1.1: Proof. In the Turán graph T r (n), any set of four vertices inducing a copy of K 4 must come from four different partite sets. Thus there are copies of K 4 in T r (n). The claim immediately follows. We will also need the following lemma from folklore characterizing multipartite graphs: Lemma 1.6. Define the co-cherry P 2 to be the unique graph on three vertices with one edge. Then G is a complete multipartite graph if and only if it does not contain the co-cherry as an induced subgraph. Proof. First, assume G is a complete multipartite graph and let x, y, z ∈ V (G) such that x is adjacent to y but z is not adjacent to y. As G is complete multipartite, the only way z is not adjacent to y is if they are in the same vertex class. As x is adjacent to y, it must be in a different vertex class. Thus x and z do not share a vertex class and are adjacent, so G[{x, y, z}] does not span a co-cherry. Now let G be a graph that does not contain the co-cherry as an induced subgraph. Define a relation on V (G) by x ∼ y if x is not adjacent to y. As G is simple, this relation is reflexive and symmetric, and if x is not adjacent to y and y is not adjacent to z, then x cannot be adjacent to z, as that would form an induced co-cherry, so the relation is transitive as well. Thefore this equivalence relation partitions the vertices of G into classes which contain no internal edges. Furthermore, two vertices from different classes are by definition adjacent and thus every edge between vertex classes is present. We conclude G is complete multipartite.

The Flag Algebra Method
Flag algebras were introduced by Razoborov [24] as a tool to computationally solve problems in extremal combinatorics. In this section, we will introduce some of the main ideas necessary for our proof. For a complete overview see [24]. Flag algebras have been applied to study a variety of extremal problems on graphs [4,5,14,17,25] and hypergraphs [10,13,23], as well as oriented graphs [7,18]. These only represent a handful of the many results in combinatorics which were obtained using flag algebras.
A type σ is a graph labelled by [k]. An embedding of σ into a graph F is an injective map θ : [k] → V (F ) so that im(θ) is isomorphic to σ. A σ-flag (F, θ) is a graph F together with an embedding θ of σ into V (F ). We will let F σ denote the set of all σ-flags up to isomorphism and F σ n denote the associated subset containing all σ-flags on n vertices. If σ is the empty graph, then we will drop it from the notation and simply use F to denote the set of all graphs, or F n to denote the set of all graphs on n vertices. As an example, if σ * is the following labelled graph on two vertices, For a type σ labelled by [k], two σ-flags (H, θ 1 ) and (G, θ 2 ), and a set X 1 of size |V (H)|−k selected uniformly at random from V (G) \ im(θ 2 ), P ((H, θ 1 ), (G, θ 2 )) is the probability that X 1 ∪ im(θ 2 ) is isomorphic to (H, θ 1 ). For completeness, if |V (G)| < |V (H)|, then we let P (H, G) = 0. If σ is the empty graph, then we will write P (H, G) to mean P ((H, θ 1 ), (G, θ 2 )). In this case, the definition of P (H, G) coincides with the standard notion of induced density. Using the same type σ * from the previous example: , then P ((H, θ 1 ), (G, θ 2 )) = 1 3 .
Thus, as the size of G tends toward infinity, we can assume that we select X 1 and X 2 independently.
Let RF σ be the set of all finite formal linear combinations of elements from F σ . For a given type σ, let K σ denote the linear subspace of RF σ generated by all elements of the form where |V (F )| < n. Razborov showed that there exists an algebra A σ = RF σ /K σ with well defined addition and multiplication. Addition is defined in the natural way by adding coefficients. For example, if F 1 , F 2 ∈ A σ * such that .
For a fixed type σ of size k, if (F 1 , θ 1 ) and (F 2 , θ 2 ) are two elements in F σ such that then the product of F 1 and F 2 is defined as For example, if (F 1 , θ 1 ) = 1 2 and (F 2 , θ 2 ) = 1 2 then, Observe that the set F σ * 4 contains more than just the two graphs pictured in the previous equation, but in all of these other graphs, P ((F 1 , θ 1 ), (F 2 , θ 2 ); (H, θ 3 )) = 0. Multiplication in A σ is defined as an extension of multiplication in F σ .
A sequence of graphs (G n ) n≥1 , where |V (G n )| = n, is said to be convergent if for every finite graph H, the limit lim n→∞ P (H, G n ) exists. Let Hom + (A σ , R) denote the set of all homomorphisms from A σ to R such that φ(F ) ≥ 0 for each element F ∈ F σ . Razborov showed that each function φ ∈ Hom + (A σ , R) corresponds to some convergent graph sequence (G n ) n≥1 . That is, the values of φ correspond to the limits of induced densities in (G n ) n≥1 . It is often more intuitive to think of addition and multiplication operations in A σ as representing induced densities of subgraphs in some very large graph G n 0 with an error term O(n −1 0 ). For each type σ labelled by [k], Razborov also defined a function · σ : RF σ → RF, which we will refer to as the unlabelling operator. For a σ-flag is a randomly chosen injective mapping. Let F denote the graph isomorphic to F when ignoring labels. Then As an example, Finally, it can be shown using the Cauchy-Schwarz inequality that if α ∈ A σ is some expression and φ ∈ Hom

Theorem 1.3 (i)
First we will prove a lower bound by counting the number of P 3 subgraphs in the Turán graph. After that, the remainder of the section will be devoted to proving the upper bound using flag algebras.
Proof. We begin by counting the paths of length three in the Turán graph T r (n). To do so, we will first choose the central edge of the path and then select two additional vertices and describe how to attach them to the central edge.
As the Turán graph is multipartite, the central edge must fall between two of the r vertex classes. Assume for the moment that n is divisible by r. Then there are r 2 ( n r ) 2 choices for the central edge: first choose two vertex classes and select a vertex from each class. Now we consider two cases. In the first case, the P 3 intersects exactly two of the vertex classes of T r (n). In this case, as we have already selected the central edge, the two vertex classes are already specified and we need only select an additional vertex from each class. These vertices are each adjacent to a different vertex of our central edge and thus give a unique P 3 . There are ( n r − 1) 2 ways to choose these two vertices.
In the second case, the P 3 intersects at least three vertex classes of T r (n). (Note that as vertex classes contain no internal edges, the P 3 must contain vertices from more than one vertex class.) We first select this third vertex, for which there are n − 2( n r ) choices, and then select a fourth unique vertex from the remaining n − 3 options. If the fourth vertex chosen happens to share a vertex class with either end of the central edge, then there is a unique P 3 containing the four vertices with the given central edge. Otherwise, there are two ways to connect the third and fourth vertices to the central edge. However, we also select pairs of vertices of this form twice as the fourth vertex we selected was an eligible choice when we selected the third in this case. Thus either way, this method produces Putting all of our counts together, for all r ≥ 4, where the error terms accounts for the cases that n is not divisible by r. Factoring out leading leading terms gives Hence, 12 r−1 r 3 ≤ OPT r (P 3 ).
We will now prove that OPT r (P 3 ) ≤ 12 r−1 r 3 using the flag algebra method. Unlike many proofs that employ this technique, ours does not require any computer assistance for verification. With that said, this section does require the multiplication and factoring of large polynomials. The authors have included a link to SageMath code used to verify these calculations in the appendix.
Proof of Theorem 1.
denote the set of all unlabeled graphs on 4 vertices up to isomorphism, pictured below. Throughout this section, we will be working with the induced densities of subgraphs in a convergent sequence of K r+1 -free graphs (G n ) n≥1 . In order to simplify notation we will let P (F ) = lim n→∞ P (F, G n ) and similarly d(F ) = lim n→∞ d(F, G n ). Summing over all of the graphs on F 4 , we observe the following: In order to make expressions like this easier to visualize, we will often use a drawing of F in place of P (F ) in our computations. For example, if (G n ) n≥1 was the sequence of complete graphs on n vertices, then P (K 4 ) = lim n→∞ P (K 4 , G n ) = 1. Using a drawing of K 4 in order to represent this density, we would write: Fix r ≥ 4 and let (G n ) n≥1 be an arbitrary convergent sequence of K r+1 -free graphs. By the law of total probability, the (non-induced) density of the path P 3 can be expressed as the sum of induced densities of graphs on four vertices in the following way, This expression can be simplified, however, as over half of the graphs in F 4 do not contain a P 3 subgraph.
From Corollary 1.5 we obtain the following upper bound on P ( Note that ≥ 0 by (5) In the following computations, we will use two sets of labeled flags F σ 1 3 and F σ 2 3 , where By the Cauchy-Schwarz inequality, each of the following three expressions is nonnegative for all r ≥ 4.
Moreover, It can quickly verified that for all r ≥ 4, the following polynomials are all nonnegative. We can add the sum 3 j=0 p j (r)P j (r) to Equation (4) to obtain the following upper bound on For each F i ∈ F 4 , let C F i denote the coefficient of the graph F i after combining like-terms in Equation (6). This gives the following, simplified upper bound on d(P 3 ).
The following are the exact values of each C F i .
By examining leading coefficients and factoring, it is clear that for all r > 1000, We have provided a link for SageMath code which can be used to verify (8)

Stability
For two graphs G and H of the same order, the edit distance between G and H, denoted Dist(G, H), is the minimum number of adjacencies one needs to add or remove in order to change G into a graph isomorphic to H. Our goal in this section is to prove that graphs with P 3 density approaching OPT r (P 3 ) are close in structure to the Turán graph T r (n). Specifically, we prove the following lemma: Lemma 3.1. For every ε > 0, there exists an n 0 and δ > 0 such that for every K r+1 -free graph G of order n ≥ n 0 , if d(P 3 , G) ≥ OPT r (n) − δ, then Dist(G, T r (n)) ≤ εn 2 .
We prepare for the proof of Lemma 3.1 with a collection of lemmas. Several of these lemmas use the epsilon-delta paradigm, and so in the interest of legibility we have labelled the lemmas in this section by letter. We adopt the convention that ε A , for example, will always refer to the ε in Lemma A. The exception to this rule is Lemma 3.1 which uses unadorned variables.
The first lemma is the Induced Removal Lemma, proved by Alon, Fischer, Krivelevich and Szegedy [1].
Lemma 3.2 (Lemma A, Induced Removal Lemma). Let F be a set of graphs. For each ε A > 0, there exist η A and δ A > 0 such that for every graph G of order n ≥ η A , if G contains at most δ A n |V (H)| induced copies of H for every H ∈ F, then G can be made F-free by removing or adding at most ε A n 2 edges from G.
We define the set T to contain all of the graphs F ∈ F 4 for which c F = OPT r (P 3 ) in the proof of Theorem 1.3.
The following is a restatement of Lemma 2.4.3 appearing in [3]. For completeness, we will provide a short proof.
Proof. Let F * 4 denote the set of graphs F in F 4 for which lim n→∞ P (F, G n ) > 0. Then lim n→∞ F ∈F * 4 P (F, G n ) = 1, implying from Theorem 1.3(i) that For each graph H ∈ F 4 \ T , we know from the proof of Theorem 1.3(i) that C H < OPT r (P 3 ). Thus, H / ∈ F * 4 as otherwise lim . Given the fact that only those graphs in T can appear with positive density in the limit of any extremal sequence, we can now prove the following lemma.

Lemma 3.4 (Lemma B).
For each ε B > 0, there exists a η B and δ B > 0 such that any K r+1 -free graph G of order n ≥ η B satisfying d(P 3 , G) ≥ OPT r (P 3 ) − δ B contains at most ε B n 3 copies of P 2 .
Proof. Suppose that (G n ) n≥1 is some convergent sequence of K r+1 -free graphs for which lim n→∞ d(P 3 , G n ) = OPT r (P 3 ).
By inspection, none of the graphs in T contain P 2 as a subgraph. Thus from Lemma 3.3, lim n→∞ d(P 2 , G n ) = 0.
This fact immediately implies Lemma 3.4.
Next we prove that among all complete r-partite graphs on at least four vertices, the Turán graph T r (n) contains the most P 3 subgraphs.
Proof. We count the number of P 3 in a complete multipartite graph using a similar approach to that in the proof of Theorem 2.1. We sum over each edge and count the number of P 3 with that edge as the center. If e = xy is an edge in the center of P 3 with x in vertex class V x and y in vertex class V y , let the other edges of the P 3 be wx and yz. We classify the P 3 into one of four types depending on the location of w and z.
• There are (|V x | − 1)(|V y | − 1) such P 3 with w ∈ V y and z ∈ V x as we may not reselect x or y.
• When w ∈ V y but z / ∈ V x , there are (|V y | − 1)(n − |V x | − |V y |) choices for the P 3 as z falls in some vertex class other than V x or V y .
• Finally, if w / ∈ V y and z / ∈ V x , then we must take care to select them uniquely. Choosing w first and then z gives (n − |V x | − |V y |)(n − |V x | − |V y | − 1) many such P 3 .
Thus in total, for complete multipartite graphs G, Now suppose that G has r parts V 1 , . . . , V r . There are |V i ||V j | edges between parts V i and V j , each of which contributes the same term in the sum above. Thus we may also write Let G be a complete r-partite graph on n vertices with parts V 1 , . . . , V r such that |V 1 | ≥ |V 2 | + 2. If G has no edges but at least four vertices, it cannot be extremal, so assume G contains at least one edge. Define G to be the complete multipartite graph on n vertices with parts V 1 , V 2 , . . . , V r where |V 1 | = |V 1 | − 1, |V 2 | = |V 2 | + 1, and |V i | = |V i | for i ≥ 3.
Thus we see G was not extremal and therefore the Turán graph, the unique complete r-partite graph in which no pair of vertex classes differs in size by more than one, is the complete r-partite graph with the greatest number of P 3 .
In the next lemma, we prove that if G has large P 3 -density, it is close in edit distance to a nearly balanced complete r-partite graph.
Lemma 3.6 (Lemma C). For any two independent parameters ε C > 0 and γ C > 0 there are η C and δ C > 0 such that if G is a K r+1 -free graph with order n ≥ η C satisfying d(P 3 , G) > OPT r (P 3 ) − δ C , then there is a complete r-partite graph G with parts X 1 , . . . , X r satisfying Dist(G, G ) ≤ γ C n 2 and, for each 1 ≤ i ≤ r, Proof. Let ε C , γ C > 0 be given. We require a γ C > 0 but defer its exact definition until later. Take η A and δ A to be as in Lemma 3.2 so that any graph G of order n ≥ η A containing at most δ A n 3 copies of P 2 can be made P 2 -free by editing at most γ C n 2 edges. Then take η B and δ B to be as in Lemma 3.4 so that for any graph G of order n ≥ η B which satisfies d(P 3 , G) ≥ OPT r (P 3 ) − δ B contains at most δ A n 3 copies of P 2 (that is, apply Lemma 3.4 with ε B = δ A ).
Though we are not ready to define them yet, we will ensure η C ≥ max(η A , η B ) and δ C ≤ min(δ A , δ B ). Let G be a graph of order n ≥ η C satisfying d(P 3 , G) ≥ OPT r (n) − δ C . By Lemma 3.4, G has at most δ A n 3 copies of P 2 and thus by Lemma 3.2 we may edit at most γ C n 2 edges of G to get a P 2 -free graph, G . It follows from Lemma 1.6 that G is a complete r-partite graph as it is both K r+1 -free and P 2 -free. Let X 1 , . . . , X r denote the partite sets of G . We complete the proof by demonstrating these partite sets all have size nearly n r . There is a constant c > 0 such that each edge removed from G is contained in at most cn 2 copies of P 3 . (The constant c counts the number of ways to extend an edge and two other vertices into a copy of P 3 .) Thus d(P 3 , G ) ≥ OPT r (P 3 ) − δ C − cγ C as the P 3 -density of the removed edges is at most To prove that the partite sets have bounded size, we will show that if they do not, we may alter G to increase its P 3 density beyond OPT r (P 3 ). As OPT r (P 3 ) is, by definition, a limit, we can, for large enough η C , get upper bounds on the P 3 -density of such graphs that are as close to OPT r (P 3 ) as necessary to arrive at a contradiction.
We require a partial result from the proof of Lemma 3.5. Recall that when moving one vertex from vertex class V 1 to vertex class V 2 the change in the number of P 3 subgraphs was Assume first that there is a partite set that is too large. Specifically, assume, without loss of generality, that |X 1 | > 1+ε C r n. We consider two cases. First, assume There must be a partite set of G , say X 2 , that satisfies |X 2 | < n r ; if not, is a contradiction. Consider the process of moving one vertex from X 1 to X 2 repeated ε C 3r n times. At each step of this process, We take η C large enough that this value is always at least 2 so that number of P 3 subgraphs increases at every step. In particular, as |X 1 | + |X 2 | stays constant and .
Take η C large enough so that n ≥ η C implies n − 3 ≥ n 2 and ε C 3r n − 1 ≥ ε C 4r n, giving Now, as we repeat this process ε C 3r n times, the total increase in the number of copies of P 3 is at least ε C 3r n · ε C 32r n 3 = ε 2 C 96r 2 n 4 .
As |V (P 3 )| = 4, this increases the P 3 density of G by at least ε 2 C 96r 2 . By choosing δ C and γ C such that a contradiction for large enough η C . Otherwise we have |X 1 | ≥ n 2 . We wish to use a similar approach to the first case, but we must assure that the lower bound on ∆ P 3 is cubic in n at each step of the process. Note that for 2 ≤ i ≤ r, we must have |X i | ≤ 1 2(r−1) n ≤ 1 6 n (recall r ≥ 4). We start by moving n 12 vertices from X 1 to X 2 . These moves increase the number of copies of P 3 , but we disregard those increases. Then we have |X 1 | > n 2 − n 12 = 5 12 n and n 12 ≤ |X 2 | ≤ n 6 + n 12 = 3 12 n.
Starting from this modified graph we can move n 24 additional vertices from X 1 to X 2 . For each such move, we have by choosing η C large enough, and again with η C large enough. Thus and repeating this process n 24 times increases the total number of P 3 subgraphs by at least n 4 5616 , increasing the P 3 density of G by 1 5616 . By taking δ C + cγ C < 1 5616 we again get a graph with P 3 density larger than the optimal density, a contradiction when η C is sufficiently large.
Finally, we now assume for contradiction that |X 1 | < 1−ε C r n. If |X 1 | < 1−(r−1)ε C r n, then there must be another partite set X i with |X i | > 1+ε C r n as otherwise is a contradiction. As we have already handled cases with a too large part, we may assume There must be a partite set X i with |X i | > n r , again because otherwise the parts combined cannot contain n vertices. Then we move a vertex from X i to X 1 and repeat the move ε 3r n times. Then as before at every step of the process and, using very rough bounds, Therefore this process also increases the P 3 density of G by at least ε 2 C 96r 2 , a contradiction for δ C small enough. We conclude each partite set X 1 , . . . , X r must be within the specified bounds.
For completeness, we explicitly specify our choices of η C , δ C , and γ C . We set where η C is also large enough to guarantee all graphs of this form are sufficiently close to OPT r (P 3 ). These choices assure that we can combine Lemmas 3.2 and 3.4 to produce a G with Dist(G, G ) ≤ γ C n 2 ≤ γ C n 2 also that 96r 2 , as well as the bounds we use on n, all hold.
We are now ready to prove Lemma 3.1. Proof of Lemma 3.1. Let ε > 0 be given. Set n 0 = η C and δ = δ C from Lemma 3.6 with γ C = ε/2 and ε C = ε/2r. Then given a graph G of order n ≥ n 0 that satisfies d(P 3 , G) ≥ OPT r (P 3 ) − δ, we get a complete r-partite graph G satisfying Dist(G, G ) ≤ ε 2 n 2 and with parts X 1 , . . . , X r satisfying We claim Dist(G , T r (n)) ≤ ε 2 n 2 . From each of the r parts, at most ε 2r n vertices must be added to or removed from that part. Thus in total, ε 2 n vertices are altered. Each vertex requires changing at most n adjacencies, so the total edit distance is bounded above by ε 2 n 2 . Finally, by first making the at most ε 2 n 2 edits to change G into G and then making the at most ε 2 n 2 edits to change G into T r (n), we have demonstrated Dist(G, T r (n)) ≤ εn 2 , completing the proof.

Exact Result
In this section we will prove Theorem 1.3(ii). We now know that for large enough n, if G is an n-vertex K r+1 -free graph that is close to being extremal, then G is close in edit-distance to T r (n). As we will show in this section, the process of adding or removing the necessary edges in order to transform G into T r (n) must increase the number of P 3 -subgraphs in G. First we need the following proposition, which shows that in any extremal graph each pair of vertices must be contained in approximately the same number of P 3 -subgraphs. We define ν G (v, T ) as the number of (not necessarily induced) subgraphs of a graph G isomorphic to T containing v.
Proposition 4.1. Fix r ≥ 4. Then there exists an n 0 = n 0 (r) such that if G a K r+1free graph on n ≥ n 0 vertices for which ν(P 3 , G) = ex(n, P 3 , K r+1 ), then for every vertex v ∈ V (G) Proof. From the proof of Theorem 1.3(i), there must exist some n 0 such that for every extremal graph G on n ≥ n 0 vertices. Suppose that G is such a graph on n ≥ max{n 0 , 2r 4 } vertices. We count the copies of P 3 in G in two ways to see Thus, by averaging there must exist some vertex u ∈ V (G) for which Suppose for contradiction that for some vertex v ∈ V (G), Let G be the graph obtained from G by deleting v and replacing it with a vertex u so that N (u ) = N (u). We claim that G is K r+1 -free. Suppose for contradiction that it is not. Then u must be contained in every copy of K r+1 in G . As u is not adjacent to u , none of these K r+1 contain u. However, since N (u) = N (u ), this implies that we can replace u with u in each (r + 1)-clique. Since V (G ) − {u } = V (G) − {v}, this implies the existence of an (r + 1)-clique in G, which is a contradiciton.
We will also require the following proposition much later in the proof of Theorem 1.3(ii), where we will provide more explanation of why it is required. For completeness, we will state it here.
(ii) n 0 ≥ 2r 4 and is large enough to satisfy the conditions of Proposition 4.1.
(iii) n 0 is large enough to satisfy the conditions of Proposition 4.2.
Let G be an extremal graph on n ≥ n 0 vertices. Recall that (i) means that we can transform G into T r (n) by changing at most 2 r 10 n 2 adjacencies. We will call each edge removed in the process of transforming G into T r (n) a surplus edge, and each added edge a missing edge. Let b(v) denote the total number of surplus edges and missing edges incident with a vertex v. If v is a vertex for which b(v) > 1 r 5 n, then we say that v is a bad vertex. Partition the vertex set of G into sets X 1 , X 2 , . . . , X r so that after changing all required adjancencies in G the sets X 1 , X 2 , . . . , X r are the partite sets of T r (n). For the moment, move each bad vertex from its original set and place it into a new set X 0 . Claim 4.3. |X 0 | ≤ 1 r 5 n. Proof. Since Dist(G, T r (n)) ≤ 2 r 10 n 2 and each vertex v ∈ X 0 satisfies b(v) > 1 r 5 n, Claim 4.3 follows immediately. Now we will show that all surplus edges must be incident with at least one vertex in X 0 . This will allow us to focus only on the bad vertices. For a finite collection of vertices x 1 , x 2 , . . . , x ∈ V (G) let N (x 1 , x 2 , . . . , x ) denote the common neighborhood of x 1 , x 2 , . . . , x , which is the set of vertices in V (G) adjacent to each of x 1 , x 2 , . . . , x . Proof. Suppose for contradiction that for two vertices u and v in X j \ X 0 are adjacent for some integer j ∈ [r]. By symmetry we may assume that j = 1. Since neither vertex is contained in X 0 , both u and v are incident with at most 1 r 5 n missing edges in X 2 \ X 0 . This implies that there are at most 2 r 5 n vertices in X 2 \ X 0 not contained in N (u, v). Since Claim 4.3 implies that we have moved at most 1 r 5 n vertices from X 2 to X 0 , Let w 2 be one of the vertices contained in the set (N (u, v) ∩ X 2 ) \ X 0 . Then uvw 2 induces a triangle in G. Since w 2 is also only incident with 1 r 5 n missing edges, we can apply an identical argument using u, v, w 2 and the set X 3 to show: implying that we can find some w 3 ∈ X 3 such that uvw 2 w 3 induces a K 4 in G. Continuing this process for each j ∈ {4, . . . , r}, we can always select one vertex w j ∈ X j in an identical manner so that uvw 2 . . . w j induces a copy of K j+1 in G. This is possible since |(N (u, v, w 2 , . . . , w j−1 ) ∩ X j ) \ X 0 | ≥ n r − (j + 1)n r 5 > 0 for each j. This, however, would imply that after selecting vertices u, v, w 2 , . . . , w r−1 that induce a copy of K r , |(N (u, v, w 2 , . . . , w r−1 ) ∩ X r ) \ X 0 | ≥ n r − (r + 1)n r 5 > 0.
Thus, we can select a vertex in X r that is adjacent to each of u, v, w 2 , . . . , w r−1 . This, however, induces a copy of K r+1 in G which is a contradiction.
For each i ∈ [r], let d i (v) = |(N (v) ∩ X i ) \ X 0 |. We say that v ∈ X 0 is a type 2 vertex if d i (v) > 0 for all i = 1, . . . , r. Otherwise, if there exists some i ∈ [r] for which d i (v) = 0, then v is a type 1 vertex.
Thus, by Proposition 4.1, vertex v cannot exist in G under the assumption that G is extremal. Since u and v were arbitrarily chosen, this completes the proof of Claim 4.8.
Proof of Theorem 1.3(ii), continued. From Claim 4.8, if two vertices u and v in X 0 have the property that d i (u) = d i (v) = 0 for some i ∈ [j], then u and v cannot be adjacent. Thus, we can take each vertex in X 0 (since each vertex is a type 1 vertex) and place it in some partite set so that G is a an r-partite graph. Adding the necessary edges to make G a complete r-partite graph, however, would increase the number of P 3 subgraphs in G. As we have already shown by Proposition 3.5 that the Turán graph is best possible among all complete r-partite graphs, this completes the proof of Theorem 1.3(ii).

Concluding Remarks
The main result in this paper follows a similar approach to that used in [19], which determined that the five cycle C 5 is also K r+1 -Turán-good for r ≥ 3. It is likely that this method could be applied to other graphs, perhaps including P 4 or C 6 . However, as the number of vertices in the target graph increases, the number of graphs considered in the flag algebra step grow exponentially and the number of cases in the stability result increase as well. Therefore, the authors believe a different method will need to be used to investigate the conjecture of Gerbner and Palmer that P is K r+1 -Turán-good for all values of .