Cycle Detection : Graphs

I have implement cycle detection algorithm in un-directed graph. It is implemented in java. It’s not producing correct output. For acyclic graph also it’s saying cycle is present. Can you please check where is the modification required ?

IDE : https://ide.codingblocks.com/s/210962

you assumed that the graph is fully connected. try to draw graph for this case and you will see problem in your code:
9 8
0 2
2 3
3 4
4 1
5 6
6 7
7 5
8 7

the fixed code can be found here: https://ide.codingblocks.com/s/211608

I have assumed that the node numbering is 0-based.