function labels = union(x, y, labels)
    %fprintf('union\n');
    %fprintf('x: %d y: %d \n', x, y);
    fx = find_val(x,labels);
    fy = find_val(y,labels);
    %fprintf('find(x): %d, find(y): %d\n', fx, fy);
    labels(fx) = fy;
end