That day Qige bursting with passion solve a hard acm’s promble on ZSTU_ACM_laboratory.
Because Qige must solve the problem to prove he is an AC_Man.but the problem is so KengDie . Qige fighting for Being an AC_Man throughout the night .There are many traps that we can describe there are some Small KENGs and Big KENGs. Can you be an AC_Man; Following is that problem.
AC Goal was in a maze of magic.The maze is described as a N * M (2<=N, M <= 50) matrix. There are WALLs, ROADs, Small KENGs and Big KENGs in the maze. Qige want get the AC Goal. We assume that " get the AC Goal " is to get to the maze where AC Goal stays. When there's a KNEG in the grid, we will fall into it so we must climbed out of the KENG. We assume that we moving up, down, right, left takes 1 unit time, and Climbed out of the Small KENG takes 1 unit time, and Climbed out of the Big KENG takes 2 unit time .
You have to calculate the minimal time to approach AC Goal. (We can move only UP, DOWN, LEFT and RIGHT, to the neighbor grid within bound, of course.)