For any two distinct vertices u and v, we say that the distance between u and v is the shortest length of the route between u and v. Consider a graph G∗ with vertex set {x1,x2,…,x3n2−n,y1,y2,…,yn}, where yi and xi are adjacent (1≤i<j≤n), xi and xj are not adjacent (1≤i<j≤3n2−n), xi and yj are adjacent if and only if i≡j(modn). Thus, the degree of each xi is 1, and the degree of yi does not exceed
n−1+n3n2−n=4n−2.
It is easy to see that the distance between xi and xj is not greater than 3. So graph G∗ satisfies the condition of the problem. G∗ has N=3n2−n+Cn2=27n2−23n edges.
In the following, we show that any graph G=G(V,E) satisfying the condition of the problem has at least N edges. Let X⊆V be the set of vertices with degree 1, Y⊆(V∖X) be the set of remaining vertices adjacent to X, and Z⊆V∖(X∪Y) be the set of remaining vertices adjacent to Y. Let W=V∖(X∪Y∪Z). We will point out the following facts.
Property 1. Any two vertices in Y are adjacent. This is because of the fact that if y1,y2∈Y are two vertices, there exist x1,x2∈X that are adjacent to y1 and y2, respectively; hence y1 and y2 are adjacent since the distance between x1 and x2 is not greater than 3.
Property 2. The distance between vertex in W and vertex in Y is 2. This is because of the fact that if the distance between w0∈W and y0∈Y is greater than 2 (obviously, distance >1), suppose that x0∈X is adjacent to y0, then the distance between w0 and x0 is greater than 3, which is a contradiction. Furthermore, we know this Property 2 means each vertex in W is adjacent to some vertex in Z.
Denote by x,y,z and w the numbers of elements in sets X,Y,Z and W, respectively. Now count the number of edges; there are Cy2 edges between points in Y, x edges from points of X to Y, at least z edges from points of Z to Y, and at least w edges from points of W to Z. So, if y≥n, then
∣E∣≥Cy2+x+z+w=3n2+Cy2−y≥3n2+Cn2−n=N,
and if y≤n−1, since each degree of vertex is at most 4n,
x+zω≤y(4n−(y−1))=y(4n+1−y)≤(n−1)(3n+2)=3n2−n−2,≥3n2−y−y(4n+1−y)≥3.
Select a vertex P in W such that P is adjacent as less as possible to vertices in Z. Suppose the least number is a, a>0 (by Property 2). Denote the set of these a vertices by NP⊆Z.
Counting the number of the edges again, there are Cy2 edges between points in Y, x edges from points of X to Y, at least y edges from points of NP to Y (by Property 2, the distance from P to vertex in Y is 2), at least z−a edges from points of Z∖NP to Y, and at least aw edges from points of W to Z. Thus,
∣E∣≥Cy2+x+y+z−a+aw=3n2−1+Cy2+(a−1)(w−1).
If a>1, then
∣E∣≥3n2−1+Cy2+(w−1)≥3n2−2+Cy2+3n2−y−y(4n+1−y)>N.
If a=1, since the degree of each vertex in W is at least 2, when we count the edges from points of W to Z, we should add at least w/2 edges, so
∣E∣≥3n2−1+Cy2+21ω≥3n2−1+Cy2+21(3n2−y−y(4n+1−y))>N.
Summing up, the least number of edges is N=27n2−23n.