Given an adjacency matrix isConnected, return the number of provinces. A province is a connected component in an undirected graph. Use DSU find operations to compress representative lookups while merging related cities.
isConnected = adjacency matrix
number of provinces
Example 1:
Input:
isConnected = [[1,1,0],[1,1,0],[0,0,1]]
Output:
2
Explanation:
Cities 0 and 1 are connected, while city 2 is isolated.
Example 2:
Input:
isConnected = [[1]]
Output:
1
Explanation:
One city means one province.
Example 3:
Input:
isConnected = [[1,0],[0,1]]
Output:
2
Explanation:
No cities are connected, so each city is its own province.