CERSOL doubt

I thought that this question could be done with graph coloring and then adding the present classes which weren’t assigned any color?

Question: Link

My Attempt: Link

Where did I go wrong?

The hints have been posted in my Codeforces blog here