#include <iostream> #include <vector> #include <queue> using namespace std; int m, n; vector<vector<bool>> visited; vector<vector<char>> square; bool legal(int i, int j, char a, char b) { if (visited[i][j]) return false; if (i < 0 || i >= m || ...