/* -*- coding: utf-8 -*- * * 1266.cc: No.1266 7 Colors - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int C = 7; const int MAX_GN = MAX_N * C; /* typedef */ typedef vector vi; struct UFT { int links[MAX_GN], ranks[MAX_GN], sizes[MAX_GN]; UFT() {} void init(int n) { for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1; } int root(int i) { int i0 = i; while (links[i0] != i0) i0 = links[i0]; return (links[i] = i0); } int rank(int i) { return ranks[root(i)]; } int size(int i) { return sizes[root(i)]; } bool same(int i, int j) { return root(i) == root(j); } int merge(int i0, int i1) { int r0 = root(i0), r1 = root(i1), mr; if (r0 == r1) return r0; if (ranks[r0] == ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; ranks[r0]++; mr = r0; } else if (ranks[r0] > ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; mr = r0; } else { links[r0] = r1; sizes[r1] += sizes[r0]; mr = r1; } return mr; } }; /* global variables */ int cbs[MAX_N]; vi nbrs[MAX_N]; UFT uft; /* subroutines */ inline int upos(int i, int j) { return i * C + j; } /* main */ int main() { int n, m, qn; scanf("%d%d%d", &n, &m, &qn); uft.init(n * C); for (int i = 0; i < n; i++) { char s[16]; scanf("%s", s); for (int j = 0, bj = 1; j < C; j++, bj <<= 1) cbs[i] |= (bj * (s[j] - '0')); for (int j = 0, bj = 1; j < C; j++, bj <<= 1) { int j1 = (j + 1) % C, bj1 = (1 << j1); if ((cbs[i] & bj) && (cbs[i] & bj1)) uft.merge(upos(i, j), upos(i, j1)); } } for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; nbrs[u].push_back(v); nbrs[v].push_back(u); for (int j = 0, bj = 1; j < C; j++, bj <<= 1) if ((cbs[u] & bj) && (cbs[v] & bj)) uft.merge(upos(u, j), upos(v, j)); } while (qn--) { int op, x, y; scanf("%d%d%d", &op, &x, &y); x--, y--; if (op == 1) { int by = 1 << y; cbs[x] |= by; int pxy = upos(x, y); vi &nbrx = nbrs[x]; for (vi::iterator vit = nbrx.begin(); vit != nbrx.end(); vit++) { int v = *vit; if (cbs[v] & by) uft.merge(pxy, upos(v, y)); } int y0 = (y + C - 1) % C, y1 = (y + 1) % C; if (cbs[x] & (1 << y0)) uft.merge(pxy, upos(x, y0)); if (cbs[x] & (1 << y1)) uft.merge(pxy, upos(x, y1)); } else { int sz = uft.size(upos(x, 0)); printf("%d\n", sz); } } return 0; }