Problem1027--「一本通 1.4 例 1」电路维修

1027: 「一本通 1.4 例 1」电路维修

Time Limit: 0 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 0
Submit Status Web Board



译自 BalticOI 2011 Day1 T3「Switch the Lamp On」
N×MN\times MN×M 个这样的元件,你想将其排列成 NNNMMM 列放在电路板上。电路板的左上角连接电源,右下角连接灯泡。

试求:至少要旋转多少个正方形元件才能让电源与灯泡连通,若无解则输出 NO SOLUTION\texttt{NO SOLUTION}NO SOLUTION
Casper is designing an electronic circuit on a N×MN ×MN×M rectangular grid plate. There are N×MN ×MN×M square tiles that are aligned to the grid on the plate. Two (out of four) opposite corners of each tile are connected by a wire.
A power source is connected to the top left corner of the plate. A lamp is connected to the bottom right corner of the plate. The lamp is on only if there is a path of wires connecting power source to lamp. In order to switch the lamp on, any number of tiles can be turned by 90°90°90° (in both directions).
In the picture above the lamp is off. If any one of the tiles in the second column from the right is turned by 90°90°90° , power source and lamp get connected, and the lamp is on.
Write a program to find out the minimal number of tiles that have to be turned by 90°90°90° to switch the lamp on.


第一行有两个整数 NNNMMM
在接下来的 NNN 行中,每行有 MMM 个字符。每个字符均为 "\texttt{\\}" 或 "/\texttt{/}/",表示正方形元件上导线的连接方向。
The first line of input contains two integer numbers NNN and MMM, the dimensions of the plate. In each of the following NNN lines there are MMM symbols – either \texttt{\\} or /\texttt{/}/ – which indicate the direction of the wire connecting the opposite vertices of the corresponding tile.


输出共一行,若有解则输出一个整数,表示至少要旋转多少个正方形元件才能让电源与灯泡连通;若无解则输出 NO SOLUTION\texttt{NO SOLUTION}NO SOLUTION
There must be exactly one line of output. If it is possible to switch the lamp on, this line must contain only one integer number: the minimal number of tiles that have to be turned to switch on the lamp. If it is not possible, output the string: NO SOLUTION\texttt{NO SOLUTION}NO SOLUTION

Sample Input

3 5

Sample Output



对于 40%40\%40% 的数据,1≤N≤4,1≤M≤51 ≤ N ≤ 4, 1 ≤ M ≤ 51N4,1M5
对于所有数据,1≤N,M≤5001 ≤ N,M ≤ 5001N,M500


Submit Status