getting WA on codechef problem FRIENDS

Problem link:RRFRNDS Problem - CodeChef
my code is :9a6lNe - Online C++ Compiler & Debugging Tool - Ideone.com
i am trying to find the no of vertices which are connected through an intermediate vertex