function [c, cs] = find_clique(jtree, nodes)
% FIND_CLIQUE Return the index of the lightest clique containing all the nodes, or -1 if none.
% [c, cs] = find_clique(jtree, nodes)
% 
% c = the index of the lighest clique containing 'nodes'.
% cs = the indices of all the cliques containing 'nodes'.
%
% We could return the index of a separator, which are always smaller than cliques,
% but it is less likely that the separator will contain the desired marginal.

cs = jtree.cliques_containing_node{nodes(1)};
for i=2:length(nodes)
  cs2 = jtree.cliques_containing_node{nodes(i)};
  cs = intersect(cs, cs2);
end
weights = jtree.clique_sizes(cs);
if ~isempty(cs)
  c = cs(argmin(weights));
else
  c = -1;
end
