Condition:
{alive _x} count units group1 < 3 && {alive _x} count units group2 < 3 && {alive _x} count units group3 < 3
Should do it. Might be a niftier way of doing it too, but that's how I'd put it. group1, group2, group3 = names of groups.
<3 ^^
Wolfrug out.