An earthquake took place yesterday and caused some of the passages in the cave to be obstructed by stones. There are four bears trapped in the cave and they want to reach each other. You have to determine the minimum number of passages that must be cleared to allow each bear to reach all the other bears.
The cave is represented as a rectangular field. Each cell in the field corresponds to a passage. Obstructed passages are denoted by '.' symbols and unobstructed passages are denoted by 'X' symbols. Bears can only move in four directions: left, right, up and down; they can't leave the field and can't walk through obstructed passages.
The first two bears are located in the first column of field and are denoted by 'B' symbols. All other cells in the first column are obstructed passages. You are NOT allowed to clear any obstructed passages in that column.
The last two bears are located in the last column of field and are denoted by 'B' symbols. All other cells in the last column are obstructed passages. You are NOT allowed to clear any obstructed passages in that column.
You will be given the cave as a rectangular field, each element of which represents a row of the cave. Your method should return the minimum number of passages that must be cleared to allow each bear to reach all the other bears.
