I have $100$ keys and $100$ safes. Each key opens only one safe, and each safe is opened only by one key. Every safe contains a random key. 98 of these safes are locked. What's the probability that I can open all the safes?
This question is confusing for me. Can you walk me through it step-by-step?
In order to open the safes, there must be at most two 'cycles' of safes and keys, and one unlocked safe in each cycle. Let $A \to B$ denote that safe A unlocks safe B. For example, if 1 and 98 are unlocked,
$$1 \to 2 \to 3 \to 4 \cdots \to 72 \to 1 \textrm{ and } 98 \to 99 \to 100 \to 73 \to 74 \to 75 \cdots \to 97 \to 98$$
is unlockable, but not if 1 and 2 are unlocked.
How many such pairs of cycles can you make? Keep in mind that there must be an unlocked safe in each cycle.
The other possibility is that they form one large cycle, like $1 \to 2 \to 3 \to 4 \cdots \to 100 \to 1$. Count those up too. If there is a large cycle, then all combinations of unlocked safes allow everything to be unlocked.
Then, we compute how many arrangements are possible, unlockable or not.
I think this generalizes nicely, actually: