function [ comp_cell ] = connected_components_v1( conn_matrix, dim )
%  This function returns the connnected components of a network.
%  Inputs:
%        conn_matrix: the connection matrix of the network
%        dim: the number of neurons in this network   
%  Output: comp_cell is a cellarray each row has information about a connected 
%          component. Specifically, an id, the number of neurons that
%          contains and the id of the neurons.

DG = sparse(conn_matrix);
nodes    = 1:dim;
cnt_comp = 0;
while(~isempty(nodes))
    [dist, path, pred] = graphshortestpath(DG,nodes(1),'directed',false);
    tot_ids  = find(dist ~= Inf);
    
    cnt_comp = cnt_comp + 1;
    comp_cell{cnt_comp, 1} = cnt_comp; %number of the connected component
    comp_cell{cnt_comp, 2} = length(tot_ids); %number of nodes
    comp_cell{cnt_comp, 3} = tot_ids; %nodes that form the connected component
    
    for i = 1:length(tot_ids)
        ids_remove = find(nodes==tot_ids(i));
        nodes(ids_remove) = [];
    end
end

