#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define BET(a,b,c) ((a)<=(b)&&(b)<(c)) #define FOR(i,n) for(int i=0,i##_end=(int(n));i VI; typedef vector VVI; struct DisjointSet { vector group ; DisjointSet(int n) : group(n, -1) { ; } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (group[y] > group[x]) swap(x, y); group[x] += group[y]; group[y] = x; } return x != y; } bool is_sameSet(int x, int y) { return root(x) == root(y); } int root(int x) { return group[x] < 0 ? x : group[x] = root(group[x]); } int size(int x) { return -group[root(x)]; } }; int M[111][111]; int main() { int w,h; cin>>w>>h; DisjointSet D(w*h); FOR(i,h) FOR(j,w) cin>>M[i][j]; auto toIndex = [w](int row, int col) { return row * w + col; }; FOR(i,h) FOR(j,w){ if(i + 1 < h) { if(M[i][j] == M[i+1][j] && !D.unionSet(toIndex(i,j), toIndex(i+1,j))){ cout<<"possible"<