Beautiful vertices Graph theory

Hi! not able to understand the problem with the logic of using BFS here https://ide.codingblocks.com/s/181723

Hey! the graph is not directed, it is an undirected graph

Thanks … this was the problem