5. Consider the problem of promotion

For an $m \times n$ grid, where $m, n$ are odd numbers not less than 3, color the grid in black and white. Under a given coloring scheme, all cells can be divided into several connected components, such that cells in the same connected component are connected to each other, and cells in different connected components are not connected. The number of connected components is denoted as $K$. We will prove the following using mathematical induction:
(1) $K \leqslant \frac{1}{4}(m+1)(n+1)+1$;
(2) When $K=\frac{1}{4}(m+1)(n+1)+1$, the cells at the four corners of the grid are not connected to any other cells.
When $m=n=3$, the eight cells on the outermost layer belong to at most four connected components that are different in color from the central cell, so $K \leqslant 5$. Equality holds if and only if the cells at the four corners are of a different color from the other five cells.

Next, assume $m \geqslant 5$. Let the second row from left to right form $k$ alternating black and white segments $A_{1}, A_{2}, \cdots, A_{k}$, with the number of cells in each segment being $x_{1}, x_{2}, \cdots, x_{4}$. Let $P$ be the number of connected components that contain cells from the first row but not from the second row.
Let $\lceil x \rceil$ denote the smallest integer not less than the real number $x$.
We now estimate $P$.
If $k \geq 2$, the last cell of the $x_{1}$ cells above $A_{1}$ is the same color as either the last cell of $A_{1}$ or the first cell of $A_{2}$, thus it is connected to a cell in the second row; among the first $x_{1}-1$ cells, at most $\left\lceil\frac{x_{1}-1}{2}\right\rceil$ cells are of a different color from $A_{1}$ and are not connected to each other. Similarly, among the cells above $A_{k}$, at most $\left\lceil\frac{x_{k}-1}{2}\right\rceil$ cells are not connected to any cell in the second row and are not connected to each other.
For $1<i<k$, among the $x_{i}-2$ cells in the middle of $A_{i}$, at most $\left\lceil\frac{x_{i}-2}{2}\right\rceil$ cells are of a different color from $A_{i}$ and are not connected to each other.
Thus, $P \leqslant\left\lceil\frac{x_{1}-1}{2}\right\rceil+\left\lceil\frac{x_{k}-1}{2}\right\rceil+\sum_{i=2}^{k-1}\left\lceil\frac{x_{i}-2}{2}\right\rceil$
$\leqslant \frac{n-k+2}{2}$.
If $k=1$, then $P \leqslant\left\lceil\frac{n}{2}\right\rceil=\frac{n-k+2}{2}$.
Let $Q$ be the number of connected components that contain cells from the second row but not from the third row. Since $A_{i}$ and $A_{i+1}$ always have one segment connected to the third row (consider the last cell of $A_{i}$ and the first cell of $A_{i+1}$, one of them must be connected to the third row), we have
$Q \leqslant\left\lceil\frac{k}{2}\right\rceil \leqslant \frac{k+1}{2}$.
Let $R$ be the number of connected components that contain cells from the third to the $m$-th row.
By the induction hypothesis (1),
$R \leqslant \frac{1}{4}(m-1)(n+1)+1$.
We now prove: If $Q=\frac{k+1}{2}$ ($k$ is odd) or $Q=\frac{k}{2}$ ($k$ is even), then
$R \leqslant \frac{1}{4}(m-1)(n+1)$.
In fact, when $k$ is odd and $Q=\frac{k+1}{2}$, if
$k=1$, then $Q=1$, all cells in the second row are the same color, and all cells in the third row are also the same color.
By the induction hypothesis (2),
$R \leqslant \frac{1}{4}(m-1)(n+1)$.
If $k$ is an odd number and $k \geqslant 3$, let the cells below $A_{i}$ be $B_{i}$. Since
$A_{1}, A_{3}, \cdots, A_{k}$ are not connected to the third row, $B_{1}$,
$B_{3}, \cdots, B_{k}$ are of the same color as $A_{1}, A_{3}, \cdots, A_{k}$. Thus, they are of the same color as $A_{2}$,
$A_{4}, \cdots, A_{k-1}$. Therefore, $B_{1}, A_{2}, B_{3}, A_{4}, B_{5}, \cdots$
$A_{k-1}, B_{k}$ are all connected.
By the induction hypothesis (2),
$R \leqslant \frac{1}{4}(m-1)(n+1)$.
When $k$ is even and $Q=\frac{k}{2}$, if
$R=\frac{1}{4}(m-1)(n+1)+1$,
then by the induction hypothesis (2), the first cell in the third row is of a different color from the second cell, so $A_{1}$ is connected to the third row. Similarly, $A_{k}$ is also connected to the third row. Thus, among $A_{2}$, $A_{3}, \cdots, A_{k-1}$, at most $\frac{k-2}{2}$ segments are not connected to the third row. Hence, $Q \leqslant \frac{k-2}{2}$, which contradicts the assumption that $Q=\frac{k}{2}$.
Therefore, when $Q=\frac{k+1}{2}$ or $Q=\frac{k}{2}$, we have
$R \leqslant \frac{1}{4}(m-1)(n+1)$.
Then $K=P+Q+R$
$\leqslant \frac{n-k+2}{2}+\frac{k+1}{2}+\frac{1}{4}(m-1)(n+1)$
$=\frac{1}{4}(m+1)(n+1)+1$.
When equality holds, $k$ must be odd, and
$P=\frac{n-k+2}{2}$.
Considering the condition for equality in the estimation of $P$, we know that the first and last cells of the first row are each surrounded by three cells of a different color.

By the symmetry of the grid, the cells at the four corners are not connected to any other cells.

It is easy to verify that for the cell at the $i$-th row and $j$-th column, if $ij$ is even, color it black; if $ij$ is odd, color it white. Under these two coloring schemes, we have
$K=\frac{1}{4}(m+1)(n+1)+1$.
In summary, the required $M=\frac{1}{4}(n+1)^{2}+1$.
5. Given an odd number $n \geqslant 3$, color each cell of an $n \times n$ grid with two colors, black and white. Two cells with the same color that share a vertex are called "adjacent". For any two cells $a$ and $b$, if there exists a sequence of cells $c_{1}, c_{2}, \cdots, c_{k}$ such that $c_{1}=a, c_{k}=b, c_{i}(i=1,2, \cdots, k-1)$ and $c_{i+1}$ are adjacent, there exists a coloring scheme in which there are $M$ pairwise disconnected cells.
（Supplied by Wang Xinmao）