Let $A\subset R^{n}$ . Then $A$ is disconnected iff there exists a continuous and surjective functon $f:A\to${0,1} Let $A\subset R^{n}$ . Then $A$ is disconnected iff there exists a continuous and surjective function $f:A\to${0,1} 
How can I prove this?
To prove $\rightarrow$, I know that if $A$ is disconnected, then there are two open, non empty and disjoint sets $U,V\subset R^n$ such that $A=U\cup V$ , $A\cap U \ne \emptyset $, $A\cap V \ne \emptyset$ and $A \cap U \cap V=\emptyset$ .
Then we define a function $f(x)=\begin{cases} 0, & x \in U \\ 1, & x \in V\\
\end{cases}$
We can see that this function is surjective because both sets are non empty and there is not an $x$ such that $f(x)=0$  and  $f(x)=1$ (the sets are disjoint). Is this correct?
Then I don't know how to prove the continuity of $f$, I've tried using the fact that $f$ is continuous iff the inverse image of an open(closed) set is open(closed) in $A$, but I still struggle using the concepts of relative open and closed sets(my professor didn't explain them very well) so I don't know how to finish the proof.
Any help will be apprecciated, thanks.
 A: The topology on $\{0,1\}$ is the discrete topology, i.e. all subsets are open. 
Restrict $f$ to $A$. All you need to check that the preimage of each open set is open. It is clear for $\{0,1\}$  are $\emptyset$, and you have shown that $f^{-1}(\{1\})=V\cap A$ (which is open in the induced topology on $A$) and $f^{-1}(\{0\})=U\cap A$ (which is open in the induced topology on $A$). So you are actually done!  
A: $'\implies '$ 
You have chosen the right function $f$ .To justify its continuity note that $\{0,1\}$ is equipped with discrete topology. So what are the open sets  available ?
They are $\{0\},\{1\},\{0,1\},\emptyset $ Then $f^{-1}(\{0\})=U;f^{-1}(\{1\})=V;f^{-1}(\{0,1\})=A;f^{-1}(\emptyset)=\emptyset$ which is open in each case.Thus $f$ is continuous.
A: Forget $\mathbb{R}^n$ and stay in the induced topology of $A$.
A space $A$ (by its own right) is connected iff (by definition) there does not exist two non-trivial, disjoint, proper, open subsets $U,V$ of $A$ such that $A=U \cup V$ .
Supposing $A$ is not connected, then there are such $U,V$. Your function $f$ defined in the way you did is continuous, because the pre-image of every open subset of $\{0,1\}$ (I assume you are considering the discrete topology) is either $\emptyset, A, U$ or $V$, hence open.
