I was rereading HPMOR and got to the math problem about love triangles (4^3 possible combinations but you need to remove the combinations where 1 person is not loved or in love with someone) and solved it by counting all the combinations that did not work (10) and subtracted it from the 64 possibility's to get 54 then did the same sort of counting strategy for if there were four people and fond that knowing the answer for 3 people made counting here easy (4 nodes (4^6) = 4096 won't include everyone (54x4)+(3x6)+1 = 235 so answer is 3861) but then, And here is my question forward is there a mathematical formula so solve for X people instead of laboriously solving by adding 1 person at a time and counting the permutations that don't include everyone?

Thank you that was bothering me that explains it perfectly.