https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm_for_logarithms
I am confused. It seems that algorithms's step x ← r−1(a2i - ai) mod p should be mod x ← r−1(a2i - ai) mod p-1, and with that, you cant just take the inverse as it is not obligatory for a2i-ai and p-1 be coprime. I also find that mistake in https://math.dartmouth.edu//~carlp/PDF/dltalk4.pdf so I dont who is right and who is wrong. Please help me.
I think you are confusing the $p$ in the algorithm with the usual $p$ for Discrete Logarithm in $\mathbb F_p$. For the latter you are solving $$ a^x \equiv b \pmod p $$ For this problem $p$ is a prime and hence if $$ a^u \equiv a^v\pmod p $$ then $$ u \equiv v\pmod{p-1} $$ But in this algorithm they assume you are solving $$ a^x = b \in G $$ in some cyclic group $G$ of order $p$ with generator $a$. Therefore it satisfies $$ a^u = a^v \Longleftrightarrow u\equiv v \pmod p $$
This algorithm is more general, since the only assumption required is that $$<a> = \{a^1,a^2,a^3,\dots,a^p=e\}$$ generates a group of order $p$. (Where $e$ is the identity of the group.)