Given an n × n adjacency matrix isConnected where isConnected[i][j] = 1 indicates a direct connection between city i and city j. Count the total number of connected components (provinces).
"This problem is classic undirected connected components. The vertices are the $n$ cities, and the adjacency matrix gives the edges directly."
"We maintain a boolean visited[n] array. We iterate $i$ from 0 to $n-1$. If city $i$ is not visited, it belongs to a new province: increment count++ and launch DFS from $i$."
"Inside dfs(u), mark visited[u] = true. Then iterate through all potential neighbors $v$ from 0 to $n-1$. If isConnected[u][v] == 1 && !visited[v], recursively explore $v$."
"Time complexity is $O(n^2)$ because we check every cell in the $n \times n$ matrix. Space complexity is $O(n)$ for the visited array and recursion stack depth."