#include using namespace std; typedef pair P; typedef pair> PP; typedef long long ll; const double EPS = 1e-8; const int INF = 1e9; const int MOD = 1e9+7; int dy[] = {0,1,0,-1}; int dx[] = {1,0,-1,0}; bool dfs(const int mm,int y,int x,int prevy,int prevx,vector>& m,vector> used){ int ny,nx; if(used[y][x] == 1)return true; used[y][x] = 1; for(int i=0;i<4;i++){ ny = y + dy[i];nx = x + dx[i]; if(ny < 0 || nx < 0 || ny > m.size()-1 || nx > m[0].size()-1)continue; if(ny == prevy && nx == prevx)continue; if(mm != m[ny][nx])continue; return dfs(mm,ny,nx,y,x,m,used); } return false; } int main(void) { int w,h; cin >> w >> h; vector> m(h,vector(w)); vector> used(h,vector(w)); for(int i=0;i> m[i][j]; } } bool ans = false; for(int i=0;i