% -------------------------------------------------------------------------

function nr=svdnormrez(v,k,a)
%
% Funkcija svdnormrez raèuna vrijednost normaliziranog reza nr
% k-particije grafa odreðene vektorom v(1:n). 
% Graf je zadan matricom susjedstva W.
%
[m,n]=size(a);
nr=0;
for sk=1:k 
    in=find(v==sk);
    if (isempty(find(in<=m))|isempty(find(in>m)))
        nr=inf;
        return
    else    
        out=find(v~=sk);
        rez=sum(sum(a(in(find(in<=m)),out(find(out>m))-m)))+ sum(sum(a(out(find(out<=m)),in(find(in>m))-m)));
        t=sum(sum(a(in(find(in<=m)),:)))+sum(sum(a(:,in(find(in>m))-m)));
        nr=nr+rez/t;
    end
end


