I have found this theorem in a calculus book
We say a function $f: I \to \Bbb{R}$, $I$ interval of $\Bbb{R}$ is connected if $\forall J \subseteq I$, with $J$ interval, $f(J)$ is an interval. Prove that if $f$ is connected and if $\forall y \in \Bbb{R} \, f^{-1}(\{y\})$ is a closed set in the relative topology of $I$, then $f$ is continuous.
I have no idea where I can start, can you give me some hints?
For $x \in I$ let $I_n(x) = I \cap (x - \frac{1}{n},x + \frac{1}{n})$. This is an open neighborhood of $x$ in $I$. We have $$(*) \phantom{xx} \bigcap_{n=1}^\infty f(I_n(x)) = \{ f(x) \} .$$ "$\supset$" is trivial. To verify "$\subset$", let $y \in \bigcap_{n=1}^\infty f(I_n(x))$. Then there exist $x_n \in I_n(x)$ such that $f(x_n) = y$. Obviously $x_n \to x$. Since $f^{-1}(y)$ is closed in $I$ , we see that $x \in f^{-1}(y)$, i.e. $f(x) = y$.
Let $\varepsilon > 0$. Since $I_n(x)$ is an interval, also $J_n = f(I_n(x))$ is an interval. We have $J_n = \langle a_n,b_n \rangle$, where $\langle a_n,b_n \rangle$ stands for an open, half-open or closed interval such that $a_n \le f(x) \le b_n$. $a_n = -\infty$, $b_n = \infty$ is allowed. The sequence $(a_n)$ is increasing, the sequence $(b_n)$ decreasing. But $(*)$ shows that $a_n, b_n \to f(x)$, hence $f(I_n(x)) = J_n \subset (f(x)- \varepsilon, f(x)+ \varepsilon)$ for sufficiently large $n$. This means that $f$ is continuous.