Added separate method to test the cycles in graph