function [I,sizes_dist] = generate_hypergraph_bis(n,K)
% n: number of vertices
% m: number of hyperedges
% K: maximum size of hyperedge
% I is the nxm incidence matrix of the hypergraph

n_edges=n*ones(1,K-1);
for i=1:K-1
    n_edges(1,i)=floor(n_edges(1,i)/(2^(i-1)));
    %n_edges(1,i)=floor(n_edges(1,i)/(2^(i)));
end
%n_edges(1,1)=300;% number of edges
%n_edges(1,2)=300;% number of 3-hyperedges
%n_edges(1,1)=0;
%n_edges=400;
m=sum(n_edges,2);
I = zeros(n,m);
%sizes_dist = sort(randi([3,K],m,1));
sizes_dist=n_edges';
idx=1;
%K=2;
for k=1:K-1
     %   idx_0=idx;
    for h=1:n_edges(k)
        new_sample=sample_without_replacement_bis(k+1,I,idx);
        I(new_sample,idx)=ones(k+1,1);
        idx=idx+1;
    end
    %Ind(1,k)=I(:,[idx_0:idx-1]);
end

end