class Unionfind { public: vector data; Unionfind(size_t size) : data(size, -1) { } bool connect(size_t x, size_t y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = (int)x; } return x != y; } inline bool same(size_t x, size_t y) { return root(x) == root(y); } inline size_t root(size_t x) { return (size_t)(data[x] < 0 ? x : data[x] = root(data[x])); } inline int size(size_t x) { return -data[root(x)]; } }; int H,W; { rd(H,W); Unionfind uf(H*W+1); int cnt;cnt = H*W+1; int p = 0; REP(y, H){ REP(x, W){ int c;rd(c); if (c == 0) cnt -= uf.connect(p, H*W); else{ if (0