The Musical Pair-CodeWars 2013: WA

I am getting wrong answer for the http://www.codechef.com/CDCL2013/problems/MPAIR question .My logic is correct but missing some test cases…kindly suggest the correction…???

my solution to the question:—http://www.codechef.com/viewsolution/2741273

try this case…

5 3
1 2
3 4
1 3

the ans ur code gives is 0 while the ans is 4…hope this helps…:slight_smile:

HINT:- use DFS!!!

I have tried to optimise and this is my solution

is this approach correct …???

which working fine but I cannot submit the solution to this question … I am new to programming …someone kindly explain the logic to solve this question through DFS or any other efficient algorithm …plz help …

//