Given a positive integer $n \geqslant 2$, non-negative real numbers $x_{1}$, $x_{2}, \cdots, x_{n}$ satisfy
$\sum_{i=1}^{n} x_{i}^{2}=1, M=\max \left\{x_{1}, x_{2}, \cdots, x_{n}\right\}$.
Find the maximum and minimum values of $S=n M^{2}+2 \sum_{1 \leqslant i<j \leqslant n} x_{i} x_{j}$.
Let $M=x_{1}$. Then
$$
\begin{aligned}
S & =n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-\sum_{i=1}^{n} x_{i}^{2} \\
& =n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-1 .
\end{aligned}
$$

By the Cauchy-Schwarz inequality, we have
$$
\begin{array}{l}
\left(\sum_{i=1}^{n} x_{i}\right)^{2} \\
\leqslant(1+\underbrace{\frac{1}{\sqrt{n}+1}+\cdots+\frac{1}{\sqrt{n}+1}}_{n-1 \uparrow}) . \\
\quad\left(x_{1}^{2}+(\sqrt{n}+1) x_{2}^{2}+\cdots+(\sqrt{n}+1) x_{n}^{2}\right) \\
=\sqrt{n} x_{1}^{2}+(n+\sqrt{n}) x_{2}^{2}+\cdots+(n+\sqrt{n}) x_{n}^{2} .
\end{array}
$$

Thus, $S \leqslant(n+\sqrt{n}) x_{1}^{2}+(n+\sqrt{n}) x_{2}^{2}+\cdots+$
$$
\begin{array}{l}
(n+\sqrt{n}) x_{n}^{2}-1 \\
=n+\sqrt{n}-1 . \\
\text { When } x_{2}=x_{3}=\cdots=x_{n} \text {, and } x_{1}=(\sqrt{n}+1) x_{2}
\end{array}
$$

When $x_{2}=x_{3}=\cdots=x_{n}$, and $x_{1}=(\sqrt{n}+1) x_{2}$, the equality holds, satisfying the requirement that $x_{1}$ is the largest.
Therefore, the maximum value of $S$ is $n+\sqrt{n}-1$.
Let $[x]$ denote the greatest integer not exceeding the real number $x$, and $\{x\}=x-[x]$.
$$
\text { Let } t=\left\{\begin{array}{ll}
{[\sqrt{n}],} & \{\sqrt{n}\}\frac{1}{2} .
\end{array}\right.
$$

Then, when $x_{1}=\cdots=x_{t}=\frac{1}{\sqrt{t}}, x_{t+1}=\cdots=x_{n}=0$, $S=\frac{n}{t}+t-1$.
We now prove that this is the minimum value of $S$.
It suffices to prove:
$$
n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-\left(\frac{n}{t}+t\right) \sum_{i=1}^{n} x_{i}^{2} \geqslant 0 \text {. }
$$

Consider the left-hand side of equation (1) as a quadratic function of $x_{2}$. Since the coefficient of the quadratic term is less than 0, the function reaches its minimum value when $x_{2}=x_{1}$ or 0.

Similarly, when $x_{3}, x_{4}, \cdots, x_{n}$ are all $x_{1}$ or 0, the left-hand side of equation (1) reaches its minimum value.

Suppose $x_{2}, x_{3}, \cdots, x_{n}$ have $s-1$ values of $x_{1}$ and the remaining $n-s$ values are 0, then
$$
\begin{array}{l}
n x_{1}^{2}+\left(\sum_{i=1}^{n} x_{i}\right)^{2}-\left(\frac{n}{t}+t\right) \sum_{i=1}^{n} x_{i}^{2} \\
=n x_{1}^{2}+s^{2} x_{1}^{2}-\left(\frac{n}{t}+t\right) s x_{1}^{2} \\
=s x_{1}^{2}\left(\frac{n}{s}+s-\left(\frac{n}{t}+t\right)\right) .
\end{array}
$$

Since the minimum value of $\frac{n}{s}+s$ is $\frac{n}{t}+t$, equation (1) holds.