Let $X$ be a connected topological space and $f:X\to\mathbb{R}$ a continuous map such that each point $x\in X$ has a neighborhood $U$ with $f(x)=\min_{y\in U} f(y)$. Show that $f$ is constant.
My attempt:
Consider $x\in X$ and $V:=\{ y\in X: f(y) \ge f(x)\}$. There exists a neighborhood $U$ of $x$ such that $U\subseteq V$. Now $V$ is closed, since $X\backslash V = f^{-1}(]-\infty, f(x)[)$ is open. I know that $f(X)$ is an interval in $\mathbb{R}$. I want to use the connectedness of $X$, but $V$ is not open, so $X=V\cup X\backslash V$ will give no additional information. I have no idea how to proceed.