easy c++
Approach:\n\nHar node ko ek baar mark karte hain, aur uske saare connected nodes ko mark karte hain.\nJo nodes mark nahi ki gayi hain, unko dekhte hain aur unke
Approach:\n\nHar node ko ek baar mark karte hain, aur uske saare connected nodes ko mark karte hain.\nJo nodes mark nahi ki gayi hain, unko dekhte hain aur unke connected nodes ko bhi mark karte hain.\nYeh process har unvisited node ke liye repeat hota hai, jisse connected components milte hain.\nTotal kitne connected components hain, woh count hota hai, aur wahi answer hai.\nTime Complexity (tc):\n\nHar node ko ek baar dekhna padta hai, aur har node ke saath connected nodes ko bhi dekhna padta hai. Isse O(V + E) time complexity aata hai, jahan V nodes hain aur E edges hain.\nSpace Complexity (sc):\n\nHar node ko mark karne ke liye ek boolean array (vis) use hoti hai. Worst case mein saare nodes mark hote hain, isliye space complexity O(V) hota hai, jahan V nodes hain.\nCode Explanation:\n\nfindCircleNum function mein har node ko dekha jata hai aur unke saath connected nodes ko DFS se mark kiya jata hai.\nHar unvisited node ke liye yeh process repeat hoti hai.\nFinal count, jo connected components ko represent karta hai, woh return kiya jata hai.\n\n# Code\n```\nclass Solution {\npublic:\nint n;\nvoid dfs(vector<vector<int>>& isConnected,int u,vector<bool>&vis){\n    vis[u]=true;\n    for(int v=0;v<n;v++){\n        if(!vis[v] && isConnected[u][v]==1 ){\n            dfs(isConnected, v,vis);\n        }\n    }\n}\n    int findCircleNum(vector<vector<int>>& isConnected) {\n        n=isConnected.size();\n        vector<bool>vis(n,false);\n        int count=0;\n        for(int i=0;i<n;i++){\n            if(!vis[i]){\n                count++;\n                dfs(isConnected,i,vis);\n            }\n        }\n        return count;\n    }\n};\n```
['Depth-First Search', 'C++']