Solution (source code)

= Solution

For a time-homogeneous <Markov chain> with <transition matrix> $P$, two states are <communicating states> when each can be reached from the other with positive probability in finitely many steps:
$$
\boxed{i\leftrightarrow j\quad\Longleftrightarrow\quad \exists m,n\ge0:\ (P^m)_{ij}>0,\ (P^n)_{ji}>0.}
$$
The convention $P^0=I$ includes communication of a state with itself.