Homeomorphism preserving distance
Solution 1:
I'll write $|x-y|$ instead of $d(x,y)$ to lighten notation. Suppose to the contrary that $|f(x)-f(y)|\ne |x-y|$ whenever $x\ne y$. For each $x\in M$ let $E_x=\{y\in M\colon |f(x)-f(y)|>|x-y|\}$ and $C_x=\{y\in M\colon |f(x)-f(y)|<|x-y|\}$. Clearly, both $E_x$ and $C_x$ are open and $M\setminus\{x\}=E_x\cup C_x$.
A point $x$ is called a non-cut point if $M\setminus\{x\}$ is connected. Every nontrivial connected compact metric space has at least two non-cut points (see Analytic Topology by Whyburn, p.54). Let $N$ be the set of all non-cut points of $M$, and let $d$ be its diameter, $d>0$. For every $x\in N$ either $E_x$ or $C_x$ is equal to $M\setminus\{x\}$.
Case 1. $E_x=M\setminus \{x\}$. In particular, for every other non-cut point $y$ we have $|f(x)-f(y)|>|x-y|$. Hence $E_y$ is nonempty, which implies $E_y=M\setminus\{y\}$ because $M\setminus\{y\}$ is connected. In other words, $f$ increases all distances between non-cut points.
Case 2. $C_x=M\setminus \{x\}$. Same reasoning as above shows that $f$ decreases all distances between non-cut points. Since $f$ can be replaced with $f^{-1}$, in the sequel we assume that Case 1 holds.
Choose two sequences $(x_n)$ and $(y_n)$ in $N$ such that $|x_n-y_n|\to d$. By passing to subsequences we may assume that both converge: $x_n\to x$ and $y_n\to y$. Clearly, $|x-y|=d$. Since $f$ is a homeomorphism, it maps $N$ onto itself. Thus $d\ge |f(x_n)-f(y_n)|>|x_n-y_n|$ for all $n$. Passing to the limit we obtain $|f(x)-f(y)|=\lim_{n\to\infty} |f(x_n)-f(y_n)|=d$. Thus, $|f(x)-f(y)|=|x-y|$, a contradiction.