I have given below my code which contains my approach which is passing the sample test case
Beautiful vertices only sample test cases not passing
check for this
6 5
1 2
1 3
2 3
3 4
3 5
I am getting answer as 2
The graph should not have a cycle or loop but in your input there is a cycle
oh my bad
r u cheking for the different components of the graph
like this
10
7
1 2
1 3
3 4
3 5
6 7
7 8
7 9
I am getting 1 as the answer
https://ide.codingblocks.com/s/85129(new code). I was not checking for the components , now I am getting it , can you please see if this code can be further optimised?
u have always done bfs(0)
the smallest value will be the master parent not necessary 0
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.