Topological space is connected, if any continious map is constant. Suppose $Y$ is discrete topology. Show that $X$ is connected, if any continuous map $f: X\rightarrow Y$ is constant.
So, we can assume that $X$ is not connected, then there exists such open $U,V$ that $U\cap V=\emptyset$, $U\cup V=X$. $f$ is continuous, so $f^{-1}(V)=\{x\in X|f(x)\in V\}$ is open for any open $V$. But I cannot combine these facts to get contradiction. Can anybody help me?
 A: Let $f$ take the value $x$ on $U$ and the value $y$ on $V$. Because we're mapping into the discrete topology, $\{ x \}$ and $\{ y \}$ are open subsets of $Y$. $f$ is not constant, but it is continuous.

As 5xum points out, I've been a bit sloppy here: I have used the fact that $x \not = y$ without justification. This implicitly assumes that $Y$ has more than one element, and in fact the theorem is false if $Y$ has only one element (because then every function $X \to Y$ is constant, not just the continuous ones).
A: The statement is not true in general.
If e.g. $Y$ is a singleton then any map $f:X\to Y$ is constant. However $X$ is not necessarily connected.
The statement is true under the extra condition that $Y$ contains at least $2$ elements.
If there are two distinct elements $u,v\in Y$ then you can define a function $f:X\to Y$ prescribed by $x\mapsto u$ if $x\in U$ and $x\mapsto v$ if $x\in V$. 
This function is not constant, but can be shown to be continuous. 
You forgot to mention that $U$ and $V$ are not empty.
A: Your statement is true if you correct it slightly:

A topological space $ X$ is connected if any continuous map from $X$ to any two-point discrete set is constant.

Proof.
I use the definition of a connected topological space given in [1]:

A topological space $X$ is connected if there does not exist a continuous map from $X$ onto a two-point discrete space.

Denote this two-point discrete space by $\{0, 1\}$. Then we can rewrite the above statement more mathematically as:
$X$ connected if:
$\neg (\exists f: X \rightarrow \{0, 1\}, f$  continuous and surjective$)$
This is equivalent to:
$$ \forall f: X \rightarrow \{0, 1\} \text{ continuous}, f \text{ not surjective}$$
$\iff$
$$ \forall f: X \rightarrow \{0, 1\} \text{ continuous}, f(X) = \{0\} \text{ or } f(X) = \{1\}$$
i.e., $ f$ is constant, as required.  $\square$
References
[1] Definition 12.1 page 114 of "Introduction to Metric & Topological Spaces", Second Edition, by Wilson A. Sutherland
