TITLE: Maximum number of edges in a graph where length of every cycle is a multiple of 3
QUESTION [7 upvotes]: I am doing a problem which asks to find the maximum number of edges in a graph on $n$ vertices which has the property that every cycle's length is a multiple of 3.
I was able to show that if $G$ contains a cycle $C$ then that cycle $C$ can not contain a chord.
The answer is $n-1$ +$\left\lfloor{\frac{(n-1)}{2}}\right\rfloor$ edges.
I proceed by induction and assumed the result is true for graph on n vertices.
Then if G has $n+1$ vertices then I reduced the problem into three cases:

There exists a vertex in G of degree 1 ( then induction takes us home)
$\delta(G)$ $\geq$$3$ where $\delta(G)$ is the minimum degree of $G$ (by observing that in this case $G$ must contain a cycle with a chord)
When neither of the first two cases hold.
I am stuck with this case. Help?

REPLY [3 votes]: First a variant of your no-chord lemma. Consider an arbitrary graph where every cycle has length a multiple of $3$, and suppose
$$ a_1 - a_2 - a_3 - \cdots - a_{3k} - a_1 $$
is such a cycle. Assume there exists a path
$$ a_i - b_1 - b_2 - \cdots - b_m - a_j $$
that contains no edge or intermediate vertex from the cycle. Then prove that $i\equiv j\pmod 3$.

Now suppose $G$ is a multiple-of-3-cycle graph with $n$ nodes and a maximal amount of edges. Then I will argue that $G$ cannot have a simple cycle
$$ a_1 - a_2 - a_3 - \cdots - a_{3k} - a_1 $$
where $k>1$. Namely, if it does. then we can collapse it to a triangle by identifying nodes whose indices are congruent modulo $3$. After this collapse, the graph still satisfies the multiple-of-3 condition: If it has a new cycle (other than the collapsed triangle) that wasn't present before, then that cycle must involve one of the collapsed nodes, but then the above lemma says it cannot involve more than one of the nodes and it corresponds to a cycle in the original graph that includes a multiple of $3$ edges in the collapsed cycle -- so there's a multiple of $3$ edges left in the collapsed graph too.
The collapse reduced both the number of nodes and the number of edges by $3(k-1)$, but we can arrange those in $k-1$ new fragments of the shape
      O
     / \
<---O---O

and attach each of those somewhere. Each fragment contributes four new edges, so we end up with more edges than we had but the same number of nodes -- contradicting the assumption that $G$ had a maximal number of edges.
So now we know that $G$ must be a tree made of triangles and single edges. And it is easily shown by induction that a graph of that shape has at most $n-1+\lfloor\frac{n-1}2\rfloor$ edges.

On the other hand, it is easy to see that $n-1+\lfloor\frac{n-1}2\rfloor$ edges can be achieved, by having one vertex have degree $n-1$ and connecting its neighbors two by two into $\lfloor\frac{n-1}2\rfloor$ triangles that share a corner (with a leaf vertex left over if $n$ is even).