Wrong answer on graph problem HOLI

I have coded the same code as the video but I am getting wrong answers on both Coding Blocks IDE as well as SPOJ
but it is showing correct answers for the test cases as well as Case 4 of Coding Blocks

Code - https://ideone.com/IXwJAx

No mentor resolved this question. i resolved it myself.

Hey @vivek_oberoi
That is great
I hope you understand all the mentors are 3rd, 4th year students who are currently giving their final exams or struggling with job interviews and thus a little less available. CB is recruiting more TAs but to hire quality TAs takes time. Also number of doubts is increasing at 2-3 times the avg rate.
I hope you understand the issue and bear with us for the time being. I assure you things will come to balance soon as more TAs are hired.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.