Getting runerror in few test cases

code:

Hey @rabhi1611 your bfs implementation and logic seems to be fine but from line number 61 your implementation is not clear to me.
See this code


And try to implement this logic. Also values are big so instead of taking int take long long int.

i am using the formula : (nC2-sum of each component (sizeC2))

Try submitting the code I have given to you, if it gets accepted then implement it like that.