Doubt in code parent[node] != negighbour

i understood the thing … parent[node] != neighbour , because i will be visiting my parent only and that should not be counted as cycle .
but , why cant i say that / / / parent[neighbour] != node . since , visited[negihbour] == true . so , i must be coming from different parent

When currently at a particular node, you will check all the neighbour of that node.If a neigbhour is already visited and that neighbour is not the parent of the current node then you can say that a cycle is present.
So accordingly you will have to check for this condition: if(visited[neighbour]==true&&neighbour!=parent[node]) then cycle is present. Consider any sample case and dry run with that. You will understand.

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.