結果
問題 |
No.1266 7 Colors
|
ユーザー |
![]() |
提出日時 | 2020-11-02 00:12:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,833 bytes |
コンパイル時間 | 1,868 ms |
コンパイル使用メモリ | 175,848 KB |
実行使用メモリ | 15,072 KB |
最終ジャッジ日時 | 2024-07-22 06:05:48 |
合計ジャッジ時間 | 8,693 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 14 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; class UnionFind{ private: vector<int> data; public: UnionFind(int n) : data(n,-1) {} int root(int i) { return data[i] < 0 ? i : data[i] = root(data[i]); } int size(int i) { return -data[root(i)]; } bool same(int x, int y) {return root(x) == root(y); } bool connected() {return size(0) == (int)data.size(); } bool unit(int i,int j){ i = root(i); j = root(j); if(size(j) > size(i))swap(j, i); if(i != j){ data[i] += data[j]; data[j] = i; } return i != j; } }; int N, M, Q; int id(int city, int color) { return city * 7 + color; } int main() { cin >> N >> M >> Q; vector<string> s(N); vector<vector<int>> hen(N); for(auto &i: s) {cin >> i; for(auto &j : i) j -= '0';}; UnionFind tree(7 * N); for(int i = 0; i < N; i++) { for(int j = 0; j < 7; j++)if(s[i][j] && s[i][(j + 1) % 7])tree.unit(id(i, j), id(i, (j + 1) % 7)); } for(int i = 0; i < M; i++) {int a, b; cin >> a >> b; a--, b--; hen[a].push_back(b), hen[b].push_back(a); for(int j = 0; j < 7; j++) { if(s[a][j] && s[b][j]) tree.unit(id(a, j), id(b, j)); } } for(int i = 0; i < Q; i++) { int t; cin >> t; if(t == 1) { int x, y; cin >> x >> y; x--, y--; auto& st = s[x]; st[y] = 1; if(st[y + 1])tree.unit(id(x, y), id(x, (y + 1) % 7)); if(st[y - 1])tree.unit(id(x, y), id(x, (y - 1 + 7) % 7)); for(auto nxt : hen[x]) { if(s[nxt][y]) tree.unit(id(x, y), id(nxt, y)); } } else { int x, y; cin >> x >> y; x--; cout << tree.size(id(x, 0)) << '\n'; } } }