#include #define x first #define y second using namespace std; using ll=long long; using pii=pair; using vi=vector; using vl=vector; #define pb push_back #define all(a) begin(a),end(a) const int N=2510,MOD=1e9+7; const char en='\n'; const ll LLINF=1ll<<60; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; int n,m,dis[N],ins[N]; string h[N]; bool bio[N]; vi ch[N],ord; void bfs(int x) { memset(dis,63,sizeof(dis)); queue q; q.push({x,0}); vi bio(n*m); while (q.size()) { int i=q.front().x; int d=q.front().y; q.pop(); if (bio[i]) continue; bio[i]=1; dis[i]=d; for (auto a: ch[i]) q.push({a,d+1}); } } void dfs1(int i) { bio[i]=1; ord.pb(i); for (auto x: ch[i]) if (ins[x] && !bio[x]) dfs1(x); } int szun(vi a,vi b) { for (auto x: b) a.pb(x); sort(all(a)); a.erase(unique(all(a)),a.end()); return a.size(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; vi im1,im2; for (int i=0;i>h[i]; for (int j=0;j=n || j1>=m || h[i1][j1]=='X') continue; ch[i*m+j].pb(i1*m+j1); } } for (int j=0;j>h[i]; for (int j=0;jMOD) { cout<<"NO\n"; exit(0); } vector pot; while (1) { int md=0; for (int i=1;i<(int)im1.size();++i) if (dis[im1[i]]