結果
| 問題 |
No.1266 7 Colors
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2020-10-24 04:06:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 325 ms / 3,000 ms |
| コード長 | 1,929 bytes |
| コンパイル時間 | 1,761 ms |
| コンパイル使用メモリ | 176,544 KB |
| 実行使用メモリ | 15,076 KB |
| 最終ジャッジ日時 | 2024-07-21 14:53:54 |
| 合計ジャッジ時間 | 8,363 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
/**
* @FileName a.cpp
* @Author kanpurin
* @Created 2020.10.24 04:06:21
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
class UnionFind {
private:
vector<int> par;
public:
UnionFind(int n) {
par.resize(n, -1);
}
int root(int x) {
if (par[x] < 0) return x;
return par[x] = root(par[x]);
}
bool unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return false;
if (size(rx) < size(ry)) swap(rx, ry);
par[rx] += par[ry];
par[ry] = rx;
return true;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size(int x) {
return -par[root(x)];
}
};
int main() {
int n,m,q;cin >> n >> m >> q;
vector<vector<int>> g(n);
vector<string> s(n);
UnionFind uf(7*n);
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < 7; j++) {
if (s[i][j] == '0' || s[i][(j+1)%7] == '0') continue;
uf.unite(7*i+j,7*i+(j+1)%7);
}
}
for (int i = 0; i < m; i++) {
int u,v;cin >> u >> v;
u--;v--;
g[u].push_back(v);
g[v].push_back(u);
for (int j = 0; j < 7; j++) {
if (s[u][j] == '0' || s[v][j] == '0') continue;
uf.unite(7*u+j,7*v+j);
}
}
while(q--) {
int t,x,y;cin >> t >> x >> y;
x--;y--;
if (t == 1) {
s[x][y] = '1';
if (s[x][(y+6)%7] == '1') uf.unite(7*x+y,7*x+(y+6)%7);
if (s[x][(y+1)%7] == '1') uf.unite(7*x+y,7*x+(y+1)%7);
for (int i = 0; i < g[x].size(); i++) {
if (s[g[x][i]][y] == '0') continue;
uf.unite(7*x+y,7*g[x][i]+y);
}
}
else {
cout << uf.size(7*x) << endl;
}
}
return 0;
}
🍮かんプリン