Can't find the reason for SIGSEGV

I’m trying to solve this simple SPOJ problem .
This is my current solution .
It’s giving me SIGSEGV runtime error at the 7th test case. I don’t think my code is going out of bounds of memory anywhere. Can somebody please help me out?

1 Like

Just saying, I found what the reason was. I assumed the graph was going to be connected which is not true. This was causing a problem. It’s fixed now.

1 Like

thanks @pale_rider , saved me from frustation :slight_smile:

there is chances of array bound , memory limit exceed .
See questions input constraints carefully.