Assume the data points are co-linear with a positive slope. Then the
\begin{equation*}
TSE(m_0,b_0) = 0
\end{equation*}
for some \(m_0\) and \(b_0\text{.}\) For this line notice that \(f(x_k) = y_k\) exactly for all data points. It is easy to show then that
\begin{equation*}
\overline{y} = m_0 \overline{x} + b_0
\end{equation*}
and
\begin{equation*}
s_y = | m_0 | s_x\text{.}
\end{equation*}
Therefore,
\begin{equation*}
s_{xy} = \sum_{k=1}^n \frac{(x_k - \overline{x})(m_0 x_k + b_0 - (m_0 \overline{x} + b_0))}{n-1} = m_0 s_x^2
\end{equation*}
Putting these together gives correlation coefficient
\begin{equation*}
r = \frac{m_0 s_x^2}{s_x m_0 s_x} = 1.
\end{equation*}
A similar proof follows in the second case by noting that
\begin{equation*}
m_0 / | m_0 | = -1.
\end{equation*}