Getting Wrong Answer for 2 out of 3 test cases

Hi

I am getting wrong answer in this question.
Here is my code: https://ide.codingblocks.com/s/615093

I also submitted the same code on leetcode and got success there.

this is the link for leetcode problem: https://leetcode.com/problems/number-of-provinces/

Please help in finding the issue.

@LPLC0111 in your code you are running dfs from node who have a edge connecting to them but if a node is not having any edge connected to it like
3
0 0 0
0 0 0
0 0 0
they your programe will output 0 but the ans is 3 you are missing those cases you have to start dfs from each node if it is not visited and increase the counter rest logic is the same
if your still have any issue feel free to ask and if clear rate my experience and mark it as resolved

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.

I didn’t understand. Can we discuss this over a call or by any other mode?

for input
3
0 0 0
0 0 0
0 0 0
ans should be 3
but your ans is 0

Your mistake is
if there are no 1 then you graph doesn’t contain anything
but it should atleast contain N nodes
so for that you have to add an edge from i to i

Modified Code

look at this you will understand
but if not feel free to aks
i will arrange a google meet for you

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.