#include#include#include#include#includeusing namespace std;vector> checknum = { {1,2},{1,-2},{2,1},{2,-1},{-1,2},{-1,-2},{-2,-1},{-2,1} };void bfs(vector>& board, vector>& numofhourse, vector>& stepnum,int n,int m){ int maxstep = board[n][m]; int step = 0; queue> que; que.push({ n,m }); vector> checkboard(board.size(), vector(board[0].size(), 0)); while (!que.empty() && step int size = que.size(); for (int i = 0; i int x = que.front().first; int y = que.front().second; que.pop(); stepnum[x][y] += step; numofhourse[x][y]++; checkboard[x][y] = 1; for (int j = 0; j int nx = x + checknum[j][0]; int ny = y + checknum[j][1]; if (nx >= 0 && nx = 0 && ny checkboard[nx][ny] = 1; que.push({ nx,ny }); } } } step++; }}int main() { int row, col; cin >> row >> col; vector> board(row, vector(col, 0)); vector> numofhourse = board; vector> stepnum(row, vector(col, 0)); int counthourse = 0; for (int i = 0; i for (int j = 0; j string temp; cin >> temp; if (temp != ".") { board[i][j] = stoi(temp); counthourse++; } } } for (int i = 0; i for (int j = 0; j if (board[i][j] > 0) { bfs(board, numofhourse, stepnum, i, j); } } } int minstep = INT_MAX; for (int i = 0; i for (int j = 0; j if (numofhourse[i][j] == counthourse) { if (stepnum[i][j] minstep = stepnum[i][j]; } } } } if (minstep == INT_MAX) { cout } else { cout } return 0;}