Prove that $G$ is an open interval for two-valued continuous function $f$ 
Suppose $G\subset \mathbb R$ is a non-empty open set such that the function $f:G \rightarrow \{0,1\}$ is a two-valued function and is continuous. Show that any two-valued function on $G$ is a constant if and only if the set $G$ is an open interval.

I am concerning about the construction of open set for set $G$ and have no idea to start off with. 

Theorem: A metric space $X$ is connected if and only if any continuous function $f:X\to \{0,1\}$ is constant. 
Proof:Suppose $X$ is connected and $f:X\to \{0,1\}$ is continuous. If $f$ is not a constant function, then $f$ is onto. Let $A=f^{-1}(0)$ and $B=f^{-1}(1)$. Then $A\cup B=X$,and $A,B\neq \emptyset$. Also note that both are proper subsets of $X$ and are open and  closed in $X$, a contradiction. 
Suppose $X$ is not connected. Let $A$ and $B$ be the disconnection. Then define $f:X\to \{0,1\}$ such that  $$f(x)=\begin{cases}
0, &\text{if $x\in A$}\\
1,&\text{if $x\in B$}
\end{cases}$$
$f$ is a non-constant continuous function(verify).
Another useful theorem is

A subset  $I$ of $\Bbb{R}$ is connected if and only if $I$ is an
  interval.

You can find a proof here.
I hope now you can complete your answer on your own.
