pls share the problem link with me
check ur updated code here->
can you tell me y u used the formula… ans=ans+ c*(v-c);
c is number of nodes in current connected components right?
that means v-c are the nodes that are not in current connected nodes right?
so if i pick one node form c and one node from v-c there will be no path between them and that is what we want.
so total how many such pairs possible?
it will be c * (v-c)
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
@aman212yadav why are doing answer/2 at the last after dfs?
accepted all testcases in hackerrank
we counting twice each pair acc to your logic