function [vertices, order] = getVerts(V,robots,option)
%simply a vertex extractor to get the vertices at the end of cell-table V for
%each agent

if nargin < 3
    error("not enough inputs")
end

if strcmp(option, 'end')
    vertices = zeros(length(robots),1);
    for i=1:length(robots)
        % pick out last non-zero element of V
        r = robots(i);
        vertices(i) = V{r}.node_list(find(V{r}.node_list,1,'last'));
    end
elseif strcmp(option, 'all')
    vertices = zeros(length(robots)*length(V{1}.node_list),1);
    order = vertices;
    rowi = 1;
    for i=1:length(robots)
        r = robots(i);
        tmp = nonzeros(V{r}.node_list);
        vertices(rowi:(rowi+length(tmp)-1)) = tmp;
        order(rowi:(rowi+length(tmp)-1)) = i;
        rowi = rowi+length(tmp);
    end
    vertices = nonzeros(vertices);
    order = nonzeros(order);
end

end