Problem LCA of SPOJ

This is the link to my code

And the Link to my que is

I am getting wrong ans …Please check and tell me where i am doing wrong and please modify it.

In the output format, you also need to print “case 1:”
Moreover, you need not make a graph for this, you can simply use visited array and parent array to check LCA, you can check out my code here.
For further reading on LCA you can refer to this article.
Hope this helps.