Problem Statement: Suppose $U \subset \mathbb{R}^n$ is open, and $f:U\rightarrow \mathbb{R}$ is a differentiable scalar field such that $\frac{d}{dx}f(x)=0$ for all $x\in U$, show that if $U$ is connected then $f$ is constant. Hint: fix $a \in U$, show that $\left\{x\in U : f(x) = f(a)\right\}$ is clopen.
We had a previous part that I feel might be helpful here. We had to show that if we have a function from an open ball to $\mathbb{R}$, and all directional derivatives are $0$ for all $x$ in the ball, that $f$ is constant. I am confident in that proof, I give it below:
The hypothesis of the mean value theorem is satisfied. We have that $A = B(a) \subseteq \mathbb{R}^n$ is open, we have that $f$ is differentiable on A because all of the directional derivatives exist and equal $0$. We also have that, since the open ball is convex, that $A$ contains a line segment with endpoints $\vec{a}$ and $\vec{a}+\vec{h}$ therefore there is a point $\vec{c}=\vec{a}+t_o \vec{h}$ with $0 < t_0 < 1$ such that $$f(\vec{a}+\vec{h}) - f(\vec{a}) = Df(\vec{c})\cdot \vec{h}$$ however from the problem statement we know that $Df(\vec{c})\cdot \vec{h}$ is zero, therefore $$f(\vec{a}+\vec{h}) - f(\vec{a}) = 0 \implies f(\vec{a} + \vec{h}) = f(\vec{a})$$ This implies that is a constant since the choice of $\vec{a}$ and $\vec{h}$ is arbitrary.
This shows immediately, to me, that the function should be constant because if the derivative is $0$ then all the directional derivatives should be zero and because the set is open, it is the union of open balls. Therefore what I have proven before holds here, but I feel like it shouldn't be that easy. Also I don't see how the hint helps me. If $a$ is the only point in U so that $f(x)=f(a)$ then the set is definitely not clopen, and even if the set is clopen then I have no clue how that helps me. Any help would be appreciated.
Hint: Let $a\in U,$ consider an open ball $B(a,r)\subset U$, for $y\in B(a,r)$, define $f_y:[0,1]\rightarrow R$ by $f_y(t)=f(a+ty)$. Show that $f$ is differentiable and its differential is zero. So you can say that for every $t\in [0,1], f_y(t)=f_y(0)=f(a)=f_y(1)=f(y)$ conclude that $\{y: f(y)=f(a)\}$ is open.