Let $f: X\to Y$ be a continuous and surjective map between compact metric spaces. Prove that there is a Borel set $B\subset X$ such that $f(B)=Y$, $f$ is one-to-one on $B$ and $f^{-1}:Y\to B$ is Borel. In other words, we can select from each of the sets $f^{-1}$ exactly one point in a way that the resulting inverse function is Borel.
My attempt: For each $y \in Y$ we can pick one element $x_y \in f^{-1}(y)$ then have a collection $B'=\{x_y: y \in Y\}.$ Now $\{x_y\}$ is Borel. But we don't know $B'$ is Borel or not! Can we make it Borel? Even if we couldn't then we can take a finite or countable subcollection B or B' and that will be Borel and $f$ is 1-1 on $B$ but we are lacking $f(B)=Y$. Please help me from here.
Theorem: If $f:X\to Y$ is a continuous mapping between compact metric spaces and $f(X)=Y$, then there is a Borel set $\mathscr{B}\subset X$ such that $f|_{\mathscr{B}}$ is one-to-one, $f(\mathscr{B})=Y$ and $f^{-1}:Y\to\mathscr{B}$ is Borel.
Proof: Suppose, initially, that $X \subset [0,1]$. Let $g:Y \to X$ be defined by $$ g(y) = \inf\{x \in X: f(x)= y \} \, . $$ Let $\mathscr{B} = g(Y)$. Obviously, $f(\mathscr{B}) = Y$, and $f$ is one-to-one on $\mathscr{B}$ with $g$ being its inverse.
It remains to show that $\mathscr{B}$ is a Borel set and that $g$ is a Borel map. For the former, observe that $$ X \backslash \mathscr{B} = \{x \in X: \exists x' \in X \quad \text{s.t.} x' < x, f(x') = f(x)\} =\bigcup_{n \in \mathbb{N}} E_n \, , $$ where $$ E_n = \{x \in X: \exists x' \in X \quad \text{s.t.} x' \leq x-\frac{1}{n}, f(x') = f(x)\} \, . $$ It suffices to show each $E_n$ is closed. Suppose $x$ is a limit point of $E_n$, i.e. there exists a sequence $\{x_k\}_k$ in $E_n$ such that $x_n \to x$. By definition there exists a sequence $\{t_k\}_k$ in $X$ such that for each $k$, $t_k \leq x_k -\frac{1}{n}$ and $f(x_k)=f(t_k)$. By compactness of $X$, after passing to a subsequence if necessary, we can assume that there exists a $t \in X$ such that $t_k \to t$. Obviously, $t \leq x - \frac{1}{n}$, and by continuity of $f$, $$ f(t) = \lim_k f(t_k) = \lim_k f(x_k) = f(x) \, . $$ This proves that $x \in E_n$. Therefore, $E_n$ is closed.
Now assume $X$ is any general compact metric space. It is well-known that there exists a compact $K \subset [0,1]$ and a continuous map $\phi: K \to X$...[left to the reader :(]