Show that $M$ is $not$ $connected$ if and only if there exists a non-constant continuous function $g$ : $M$ → ${0,1}$ Show that $M$ is $not$ $connected$ if and only if there exists a non-constant continuous function $g$ : $M$ → {0,1} (the metric space containing just the numbers $0$ and $1$, with the relative metric from $R$).
My attempt: this is far out of reach I believe.
→
If there exists a non constant continuous function g with the conditions stated above, then M is not connected.
Taking the inverse image of {0,1}, I have  connected space $X_0$ and $X_1$.
Since they are disjoint and their union = M, then M is not connected.
The backwards implication I can't see to figure out.

Suppose $M$ is not connected. Then $M=X_0\cup X_1$, where $X_0$ and $X_1$ are open, nonempty, and disjoint. What can you say about the map $f(x)=0$ if $x\in X_0$, and $f(x)=1$ if $x\not\in X_0$?
