How do i approach this problem?

i am not that good in using DFS so i read pseudocode given in hint, i didn’t understand it.
Can anyone explain the approach?

Create a visited set for keeping track of visited nodes. Then from every unvisited node apply a DFS with parent as 0. Then in the DFS function check that if node’s neighbors are visited or not. If neighbors are visited previously then we can say that cycle is found. If not then apply DFS to the neighbors with parent as called node. Hope this helps.

Closing this topic as your issue has been resolved by the community. If not Kindly un-mark the accepted solution to re-open the topic or feel free to create a new topic and post a link to this topic as a reference.