Solution (source code)

= Solution

Explore the individuals one at a time, maintaining the number of discovered but unprocessed individuals. It starts at $S_0=1$. Processing one individual removes it and adds its offspring, so
$$
S_j=1+\sum_{i=1}^j\xi_i,\qquad
\mathbb P(\xi_i=1)=p,\quad\mathbb P(\xi_i=-1)=1-p.
$$
The offspring choices make these increments independent. Exploration stops when the queue first becomes empty; every processed individual has then been counted exactly once. Hence
$$
\boxed{K=\inf\{j\ge1:S_j=0\}},
$$
with $K=\infty$ if the walk never hits zero. The increment sequence can be extended independently beyond the stopping time for probability estimates.