#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using T = tuple; template inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;} template inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;} constexpr int MOD = 1e9 + 7; constexpr int inf = 1e9; constexpr long long INF = 1e18; #define all(a) (a).begin(), (a).end() int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; class UnionFind{ public: vector par; vector rank; vector sz; int uf_size; UnionFind(int n){ par.resize(n); rank.resize(n); sz.resize(n); uf_size = n; for(int i=0; i>n>>m>>q; vector s(n); for(int i=0; i>s[i]; vector> G(n); for(int i=0; i>u>>v; u--, v--; G[u].emplace_back(v); G[v].emplace_back(u); } vector visited(7 * n, false); UnionFind uf(7 * n); for(int i=0; i que; que.emplace(i * 7 + j); while(que.size()){ int cv = que.front(); que.pop(); int cnum = cv / 7, crem = cv % 7; int nv; for(auto nxt : G[cnum]){ nv = nxt * 7 + crem; if(s[nxt][crem] == '1' && !visited[nv]){ visited[nv] = true; uf.unite(cv, nv); que.emplace(nv); } } nv = cnum * 7 + (crem + 1) % 7; if(s[cnum][(crem + 1) % 7] == '1' && !visited[nv]){ visited[nv] = true; uf.unite(cv, nv); que.emplace(nv); } nv = cnum * 7 + (crem - 1 + 7) % 7; if(s[cnum][(crem - 1 + 7) % 7] == '1' && !visited[nv]){ visited[nv] = true; uf.unite(cv, nv); que.emplace(nv); } } } } } while(q--){ int z, x, y; cin>>z>>x>>y; x--, y--; if(z == 1){ int cv = x * 7 + y; s[x][y] = '1'; int nv; for(auto nxt : G[x]){ nv = nxt * 7 + y; if(s[nxt][y] == '1'){ uf.unite(cv, nv); } } nv = x * 7 + (y + 1) % 7; if(s[x][(y + 1) % 7] == '1'){ uf.unite(cv, nv); } nv = x * 7 + (y - 1 + 7) % 7; if(s[x][(y - 1 + 7) % 7] == '1'){ uf.unite(cv, nv); } } else{ cout << uf.size(x * 7) << endl; } } return 0; }