Beautiful vertices - Graph problem

Giving wrong answer. Please help.