There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c.
A province is a group of directly or indirectly connected cities and no other cities outside of the group.
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.
It's easy to use dfs to flag the accessed city. Let me do this with go. First we init a flag array with zero to represent the city belogns to the ith province which started from 1. And when we found a city whose flag array is zero. It means this city never do the dfs before. We assign the count (started from 1) to the flag array and dfs from this city. We can only go to other cities who are connected to this city and flag is still 0 (never accessed before => otherwise we will do the infinite loop.) Then final count - 1 will be the answer.