C# - Simple DFS to count number of disjoint, each forming one friend circle
csharp\npublic int FindCircleNum(int[][] M) \n{\n\tbool[] visited = new bool[M.Length];\n\tint groups = 0;\n\n\tfor(int i = 0; i < M.Length; i++)\n\t{\n\t\tif(!
```csharp\npublic int FindCircleNum(int[][] M) \n{\n\tbool[] visited = new bool[M.Length];\n\tint groups = 0;\n\n\tfor(int i = 0; i < M.Length; i++)\n\t{\n\t\tif(!visited[i])\n\t\t{\n\t\t\tvisited[i] = true;\n\t\t\tdfs(M, i, visited);\n\t\t\tgroups++;\n\t\t}\n\t}        \n\n\treturn groups;\n}\n\nprivate void dfs(int[][] M, int node, bool[] visited)\n{\n\tfor(int neighbour = 0; neighbour < M.Length; neighbour++)\n\t{\n\t\tif(M[node][neighbour] == 1 && !visited[neighbour])\n\t\t{\n\t\t\tvisited[neighbour] = true;\n\t\t\tdfs(M, neighbour, visited);\n\t\t}\n\t}\n}\n```
[]