Maximum number of members in the math club 
Problem: Professor Liyung wants to make a math club consisting of his $40$ students. But there is a problem. Every student is enemies with two other students. And no one wills to be a member of the club if any of his enemies is already a member of the club. Let $M$ be the maximum number of members the club can have. Find the sum of all possible values of $M$. (If student $A$ is an enemy with student $B$, then student $B$ is an enemy with student $A$.)

This is a problem from a local math contest in my city held on last month. Here is the solution I think of :
My thoughts:  For every student chosen to be in the club, two students can't be a member of the club. So, the maximum number of members of the club is $20$.
I'm confused of the statement "Find the sum of all possible values of $M$" as there is only one value of $M$ in my solution. And I also believe that the problem would not be so easy as this was the second last problem in the contest and most of the problems there were not easy. But I couldn't think of other solution to the problem.
So, I want to know if my solution is correct or not. If not, what is the correct solution?
Update: A generalization to this problem has been discussed here.
 A: Let $M$ be maximal subset of students no two in it are enemy. Then each student not in $M$ has at least one enemy in $M$ and every one in $M$ has exactly two enemies in $G\setminus M$. So by double counting we have $$2\cdot |M| \geq |G|-|M|\implies |M|\geq {|G|\over 3} \implies |M|\geq 14$$
Now for the upper bound. If we consider this group $G$ of students as a graph when two vertices are connected iff they are enemies, then we see this graph is, since each vertex has degree exactly $2$, disjoint union of some cycles $C_1,C_2,...C_k$. Since $\varepsilon = 40$ we have $$ |C_1|+|C_2|+...+|C_k| = 40 $$
But we can take at most half vertices from each cycle in $M$ so $|M|\leq 20$.
All values between $14$ and $20$ can be achieved:

*

*For $|M|=14$ take every second vertex on $C_{4}$ and one vertex from each of twelve $C_3$.

*For $|M|=15$ take every second vertex on $C_{10}$ and one vertex from each of ten $C_3$.

*For $|M|=16$ take every second vertex on $C_{16}$ and one vertex from each of eight $C_3$.

*For $|M|=17$ take every second vertex on $C_{22}$ and one vertex from each of six $C_3$.

*For $|M|=18$ take every second vertex on $C_{28}$ and one vertex from each of four $C_3$.

*For $|M|=19$ take every second vertex on $C_{34}$ and one vertex from each of two $C_3$.

*For $|M|=20$ take every second vertex on $C_{40}$.

So, the result is $119$.
A: Suppose you order students into "enemy loops".  For example, start with a student (who we will give the name 1) and randomly pick one 1's enemies (who we will name 2).  Then, we pick 2's enemy who was not 1, and continue until we close the loop by getting to 1's other enemy.
The following statements hold:

*

*Every student will be in exactly one loop.  This is because each student has exactly two enemies, and the enemy property is mutual between students


*Every loop will contain at least three students.  This is because every enemy if every member of a loop will be a member of the same loop.


*There must be an even number of loops of odd size.  This comes from the fact that the total number of students is even, and that every student must be in exactly one loop


*If a loop has $N$ students, no more than $\lfloor \frac N2\rfloor$ students from that loop can be in the club.  This can be proved by use of the pigeonhole principle.


*As a result of the above, M can be taken by summing $\lfloor \frac N2\rfloor$ over every loop.


*Combining two even loops into a larger even loop has no impact on the value of M.  Combining an even sized loop with an odd sized loop has no impact on the value of M.  Combining two odd sized loop into an even sized loop increases $M$ by one.  This is because the floor operation only impacts the value if the size of the loop is odd, in which case it reduces its argument by $\frac 12$.


*We can divide our students into a maximum of 13 loops, of which a maximum of 12 can be odd.
Based on these claims, we can state that depending on the enmity distribution, we can have anywhere from $M=14$ to $M=20$, so the total of all possible values of $M$ is $\sum_{M=14}^{20}M$=119.
