Pseudo-Boolean functions and stability of graphs