Total ways possible (without any restriction) = 5 x 4 x 3 x 2 = 120
Ways when P is paired with Z = 4 x 3 x 2 = 24 (P & Z are out of the picture)
Ways when Y is not paired with anyone = 4 x 3 x 2 x 1 = 24 (Y is out of the picture)
(We also need to consider overlapping of above two cases)
Ways when both Y is not paired AND also P & Z are paired together = 3 x 2 x 1 = 6 (P, Z, and Y are out of the picture)
Total number of ways (with restrictions) = 120 - 24 - 24 + 6 (Adding 6 as we have included it in both 24's)
= 78
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
We can also think as follows:
Total number of ways with restrictions = Total ways possible (without any restriction) - Ways which break the rules
= 120 - ( 24 + 24 - 6) (Inclusion-Exclusion Principle)
= 78