Most of the solution only contain code not the full explanation. Here why we are checking the second contion in if parent[nbr]!=node . And how we are checking the cycle?
Please elaborate the problem and solution
@raj.verma5454 hey ,yes in this question you have to tell whether given undirected graph is tree or not ,so tree is graph without cycle so you have to check whether given graph contain cycle or not and that parent condition is also for checking cycle ,dry run that code and see the video of detect cycle in undirected graph,you will get it.
Please explain 2nd condition ,parent[node]!=nbr ?
@raj.verma5454 hey in video sir has explained that if parent of current !previous node then there is cycle ,please see that video as in that a proper example is given ,from that you can easily get it and do dry run again .
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.