code: private void dfs(int v, int[] cc, int id) {
          cc[v] = id;
          for (int t = 0; t < n; t++) {
              if (graph[v][t] != 0.0) {
                  if (cc[t] == -1) {
                      dfs(t, cc, id);
                  }
              }
          }
      }
docs: Depth-first search connected components of graph.
  @param v the start vertex.
  @param cc the array to store the connected component id of vertices.
  @param id the current component id.