$n \times m $ table path from left to right or up to down

60 Views Asked by At

We have a $n \times m$ table and for each cell we color one of it's diagonals prove that we have a path with colored edges from top of the grid to bottom of that or from left to right! Can anyone help me with solving this problem?

1

There are 1 best solutions below

5
On BEST ANSWER

Let $G$ be a graph, where all corners of cells are vertices and colored diagonals are edges. Also it has a left vertex $\ell$ adjacent to all leftmost corners and a right vertex $r$ adjacent to all rightmost corners.

Let $H$ be another graphs, where all middles of cell sides are vertices. Each cell gives to $H$ two internal edges that connect vertices of $H$ and don't cross colored diagonal. Also $H$ has a top vertex $t$ adjacent to all topmost middles and a bottom vertex $b$ adjacent to all bottommost middles.

If $G$ has a walk between $\ell$ and $r$ then it is what we need. It is not hard to see that otherwise $H$ has a walk between $t$ and $b$, that we can't overcome moving from $\ell$ to $r$. Inside each cell edges of $H$ are parallel to a colored diagonal. Now consider shortest walk $tv_1v_2\ldots v_kb$ between $t$ and $b$ and construct corresponding walk from top to bottom via colored diagonals. If $v_2$ is to the left of $v_1$ then we start with diagonal from the cell containing $v_1$ and $v_2$ on its sides. Otherwise $v_3$ is to the right of $v_2$ and we start with diagonal from the cell containing $v_2$ and $v_3$. Further for each pair of vertices $v_i$ and $v_{i + 1}$ of the walk we take diagonal from cell containing both vertices if it is adjacent or equal to previous diagonal taken or just skip otherwise. Selected diagonals give us walk from top to bottom. (Note that this way we can traverse some diagonals twice that is no problem, we can remove all such diagonals if needed.)

P. S. I guess there should be more elegant solution.