Criteria for connectedness

I have to prove that if, X is not the union of two disjoint non-empty closed subsets of itself, then,

Either X is empty or the only continuous functions from X to the discrete space {0,1} are the two constant functions.

Attempt at the proof:

Assume that the first one is true, and let f:X->{0,1} be continuous.

Then f inverse of zero and f inverse of one are both disjoint and closed in X.

How do i proceed further ?

Re: Criteria for connectedness

I don't understand what you mean by "Assume that the first one is true". You should assume that $\displaystyle X$ cannot be represented as the union of two disjoint non-empty closed subsets of itself. Then, also assume $\displaystyle X$ is nonempty (so, either $\displaystyle X$ is empty, in which case the proposition is true, or $\displaystyle X$ is nonempty, and you are in this case) and prove that the only continuous functions from $\displaystyle X$ to the discrete space $\displaystyle \{0,1\}$ are the two constant functions. As you said, define $\displaystyle f:X \to \{0,1\}$ as a continuous function. You learned that a function is continuous if the preimage of every closed set is closed. Since $\displaystyle \{0\}^c = \{1\}$ and $\displaystyle \{1\}^c = \{0\}$, both singleton sets are clopen (both open and closed) subsets of $\displaystyle \{0,1\}$. Since $\displaystyle f$ is continuous, $\displaystyle f^{-1}(\{0\})$ and $\displaystyle f^{-1}(\{1\})$ must both be closed. Suppose $\displaystyle x \in f^{-1}(\{0\}) \cap f^{-1}(\{1\})$. Then $\displaystyle f(x) = 0$ and $\displaystyle f(x) = 1$, implying $\displaystyle f$ is not even a function. So, the preimages must be disjoint. For any $\displaystyle x \in X$, either $\displaystyle f(x) = 0$ or $\displaystyle f(x) = 1$, so the union of the preimages must be the entire set. Suppose $\displaystyle f^{-1}(\{0\}) \neq \emptyset$. Then by the initial assumption ($\displaystyle X$ cannot be represented by the union of two disjoint, nonempty, closed subsets of itself), it must be that $\displaystyle f^{-1}(\{1\}) = \emptyset$. The other case: $\displaystyle f^{-1}(\{0\}) = \emptyset$. By the second assumption, $\displaystyle X$ is nonempty, so it must be that $\displaystyle f^{-1}(\{1\}) \neq \emptyset$. Hence, either $\displaystyle f(X) = \{0\}$ or $\displaystyle f(X) = \{1\}$.