結果
問題 | No.1266 7 Colors |
ユーザー | merom686 |
提出日時 | 2020-10-23 23:08:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 141 ms / 3,000 ms |
コード長 | 2,028 bytes |
コンパイル時間 | 963 ms |
コンパイル使用メモリ | 93,472 KB |
実行使用メモリ | 12,308 KB |
最終ジャッジ日時 | 2023-09-28 17:48:09 |
合計ジャッジ時間 | 4,663 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 75 ms
5,356 KB |
testcase_04 | AC | 126 ms
9,384 KB |
testcase_05 | AC | 80 ms
5,684 KB |
testcase_06 | AC | 131 ms
9,908 KB |
testcase_07 | AC | 140 ms
11,048 KB |
testcase_08 | AC | 130 ms
9,704 KB |
testcase_09 | AC | 117 ms
8,260 KB |
testcase_10 | AC | 113 ms
7,964 KB |
testcase_11 | AC | 87 ms
6,164 KB |
testcase_12 | AC | 96 ms
6,816 KB |
testcase_13 | AC | 100 ms
7,292 KB |
testcase_14 | AC | 79 ms
5,636 KB |
testcase_15 | AC | 141 ms
11,164 KB |
testcase_16 | AC | 95 ms
6,692 KB |
testcase_17 | AC | 137 ms
10,708 KB |
testcase_18 | AC | 66 ms
12,308 KB |
testcase_19 | AC | 69 ms
11,908 KB |
testcase_20 | AC | 69 ms
11,956 KB |
testcase_21 | AC | 40 ms
4,380 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; struct UnionFind { UnionFind(int n) : p(n, -1) {} int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); } int size(int u) { return -p[root(u)]; } bool same(int u, int v) { return root(u) == root(v); } void unite(int u, int v) { u = root(u); v = root(v); if (u == v) return; if (p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; } vector<int> p; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m >> q; constexpr int C = 7; UnionFind uf(n * C); vector<char[C]> s(n); for (int i = 0; i < n; i++) { char c[C + 1]; cin >> c; for (int j = 0; j < C; j++) { s[i][j] = c[j] - '0'; } for (int j = 0; j < C; j++) { if (s[i][j] && s[i][(j + 1) % C]) { uf.unite(i * C + j, i * C + (j + 1) % C); } } } vector<vector<int>> e(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; e[u].push_back(v); e[v].push_back(u); for (int j = 0; j < C; j++) { if (s[u][j] && s[v][j]) { uf.unite(u * C + j, v * C + j); } } } while (q--) { int t, x, y; cin >> t >> x >> y; x--; y--; if (t == 1) { s[x][y] = 1; if (int j = (y + 1) % C; s[x][j]) uf.unite(x * C + y, x * C + j); if (int j = (y + C - 1) % C; s[x][j]) uf.unite(x * C + y, x * C + j); for (int v : e[x]) { if (s[v][y]) { uf.unite(x * C + y, v * C + y); } } } else { cout << uf.size(x * C) << '\n'; } } return 0; }