1. Given a positive integer $n \geqslant 2$, let non-negative real numbers $x_{1}, x_{2}, \cdots, x_{n}$ satisfy $x_{1}+x_{2}+\cdots+x_{n}=n$. Find the maximum and minimum values of $\sum_{i=1}^{n-1}\left(x_{i}-1\right)\left(x_{i+1}-1\right)$.
1. Note that,
$$
\begin{aligned}
f & =\sum_{i=1}^{n-1}\left(x_{i} x_{i+1}-x_{i}-x_{i+1}+1\right) \\
& =\sum_{i=1}^{n-1} x_{i} x_{i+1}+x_{1}+x_{n}-(n+1) .
\end{aligned}
$$

When $n=2$, $x_{1}+x_{2}=2, f=x_{1} x_{2}-1$.
Since $x_{1}, x_{2}$ are non-negative real numbers, we have $f \geqslant-1$.
When $x_{1}=0, x_{2}=2$, $f$ achieves its minimum value -1.
By the AM-GM inequality,
$$
f=x_{1} x_{2}-1 \leqslant\left(\frac{x_{1}+x_{2}}{2}\right)^{2}-1=0 \text {. }
$$

When $x_{1}=x_{2}=1$, $f$ achieves its maximum value 0.
When $n \geqslant 3$, note that $x_{1}, x_{2}, \cdots, x_{n}$ are non-negative real numbers. Then $f \geqslant-(n+1)$.

When $x_{1}=x_{2}=\cdots=x_{n-2}=x_{n}=0, x_{n-1}=n$, $f$ achieves its minimum value $-(n+1)$.
Next, we prove a lemma.
Lemma For a positive integer $n \geqslant 4, a_{1}, a_{2}, \cdots, a_{n}$ are non-negative real numbers. Then
$$
4 \sum_{i=1}^{n} a_{i} a_{i+1} \leqslant\left(\sum_{i=1}^{n} a_{i}\right)^{2}\left(a_{n+1}=a_{1}\right) .
$$

Proof When $n=4$,
$$
\begin{array}{l}
\left(a_{1}+a_{2}+a_{3}+a_{4}\right)^{2} \\
\geqslant 4\left(a_{1}+a_{3}\right)\left(a_{2}+a_{4}\right) \\
=4 \sum_{i=1}^{4} a_{i} a_{i+1},
\end{array}
$$

where $a_{5}=a_{1}$.
Thus, the lemma holds for $n=4$.
Assume the lemma holds for $n=k$, then
$4 \sum_{i=1}^{k} a_{i} a_{i+1} \leqslant\left(\sum_{i=1}^{k} a_{i}\right)^{2}$.
For $n=k+1$, let $a_{1}=\max \left\{a_{1}, a_{2}, \cdots, a_{k+1}\right\}$.
By the induction hypothesis,
$$
\begin{array}{l}
\left(\sum_{i=1}^{k+1} a_{i}\right)^{2}=\left(\sum_{i=1}^{k-1} a_{i}+a_{k}+a_{k+1}\right)^{2} \\
\geqslant 4\left[\sum_{i=1}^{k-2} a_{i} a_{i+1}+a_{k-1}\left(a_{k}+a_{k+1}\right)+\left(a_{k}+a_{k+1}\right) a_{1}\right] \\
\geqslant 4 \sum_{i=1}^{k+1} a_{i} a_{i+1} .
\end{array}
$$

Thus, the lemma holds for $n=k+1$.
By the principle of mathematical induction, the lemma is true.
Returning to the original problem.
By the lemma,
$$
\begin{aligned}
f & =\sum_{i=1}^{n-1} x_{i} x_{i+1}+x_{1}+x_{n}-(n+1) \\
& =\sum_{i=1}^{n-1} x_{i} x_{i+1}+x_{n} \cdot 1+1 \cdot x_{1}-(n+1) \\
& \leqslant \frac{1}{4}\left(\sum_{i=1}^{n} x_{i}+1\right)^{2}-(n+1) \\
& =\frac{(n+1)^{2}}{4}-(n+1) \\
& =\frac{(n+1)(n-3)}{4} .
\end{aligned}
$$

When $x_{1}=\frac{n+1}{2}, x_{2}=\frac{n-1}{2}, x_{3}=x_{4}=\cdots=x_{n}=0$, $f=\frac{(n+1)(n-3)}{4}$.
Thus, the maximum value of $f$ is $\frac{(n+1)(n-3)}{4}$.
In summary, when $n=2$, the minimum value of $f$ is -1, and the maximum value is 0; when $n \geqslant 3$, the minimum value of $f$ is $-(n+1)$, and the maximum value is $\frac{(n+1)(n-3)}{4}$.