結果
| 問題 |
No.1266 7 Colors
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2020-10-23 22:51:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 332 ms / 3,000 ms |
| コード長 | 1,544 bytes |
| コンパイル時間 | 1,796 ms |
| コンパイル使用メモリ | 172,844 KB |
| 実行使用メモリ | 16,260 KB |
| 最終ジャッジ日時 | 2024-07-21 11:58:40 |
| 合計ジャッジ時間 | 8,436 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
struct dsu {
vector<int> V;
vector<int> Z;
dsu(int n) { V.resize(n); Z.assign(n, 1); rep(i, n) V[i] = i; }
int root(int a) { if (V[a] == a) return a; return V[a] = root(V[a]); }
void unite(int u, int v) { u = root(u); v = root(v); if (u == v) return; V[u] = v; Z[v] += Z[u]; }
int size(int a) { return Z[root(a)]; }
};
int N, M, Q;
bool X[100000][7];
vector<int> E[100000];
int main() {
cin >> N >> M >> Q;
dsu G(N * 7);
rep(i, N) rep(x, 7) {
char c; cin >> c;
X[i][x] = (c == '1');
}
rep(i, N) rep(x, 7) {
if (X[i][x]) if (X[i][(x + 1) % 7]) G.unite(i * 7 + x, i * 7 + (x + 1) % 7);
}
rep(i, M) {
int u, v; cin >> u >> v; u--; v--;
rep(x, 7) if (X[u][x]) if (X[v][x]) G.unite(u * 7 + x, v * 7 + x);
E[u].push_back(v);
E[v].push_back(u);
}
rep(q,Q){
int c; cin >> c;
if (c == 1) {
int x, y; cin >> x >> y; x--; y--;
X[x][y] = true;
if (X[x][(y + 1) % 7]) G.unite(x * 7 + y, x * 7 + (y + 1) % 7);
if (X[x][(y + 6) % 7]) G.unite(x * 7 + y, x * 7 + (y + 6) % 7);
for (int e : E[x]) {
if (X[e][y]) G.unite(x * 7 + y, e * 7 + y);
}
}
if (c == 2) {
int x, z; cin >> x >> z; x--;
cout << G.size(x * 7) << endl;
}
}
return 0;
}
Nachia