We’re preparing your current view and syncing the latest data.
There are n cities. Some of them are directly connected, while some are not. If city A is directly connected to city B, and city B is directly connected to city C, then city A is indirectly connected to city C. A province is a group of directly or indirectly connected cities. You are given an n x n matrix isConnected where isConnected[i][j] = 1 if the ith city and the jth city are directly connected, and isConnected[i][j] = 0 otherwise. Return the total number of provinces.
An integer matrix isConnected of size n x n representing the connectivity between cities, where 1 indicates a direct connection and 0 indicates no direct connection.
An integer representing the number of provinces (connected components) in the graph.
1 <= n <= 200 isConnected[i][j] is 0 or 1 isConnected[i][i] == 1 for all i isConnected[i][j] == isConnected[j][i] for all i, j