DWITE
December 2011
Problem 4
ABCA Maze

It's the night before DWITE, and we're a question short. I just finished my exams a few hours ago, but AJ is gone, studying somewhere in the bowels of University's campus. Though instead of recycling an old question, here's a new one, albeit with a generic story.

You suddenly find yourself to be a letter A, and also in a maze. Your task is to locate letter B, then letter C, then return to your starting point. Why are you doing this? I don't know. But you need to also find the shortest distance that this can be accomplished in.

You can move only up/down/left/right, not through walls, and not outside of the maze's bounds.

The input file DATA4.txt will contain 5 test cases. Each case will start with 2 space separated integers 1 <= R, C <= 10, Rows and Columns that describe the size of a maze, followed by R lines, each C characters long -- the actual maze.

The output file OUT4.txt will contain 5 lines of output, each the shortest distance for the A -> B -> C -> A circuit.

Sample Input (first 2 shown):
 
1 6
#A.BC#
3 6
##A###
#C.###
##...B
		        
Sample Output (first 2 shown):
 
6
12