結果
| 問題 |
No.1266 7 Colors
|
| コンテスト | |
| ユーザー |
leaf_1415
|
| 提出日時 | 2020-10-23 22:30:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 286 ms / 3,000 ms |
| コード長 | 2,075 bytes |
| コンパイル時間 | 3,013 ms |
| コンパイル使用メモリ | 86,408 KB |
| 実行使用メモリ | 21,328 KB |
| 最終ジャッジ日時 | 2024-07-21 11:18:59 |
| 合計ジャッジ時間 | 7,377 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18
using namespace std;
typedef long long llint;
typedef pair<llint, llint> P;
struct UnionFind{
int size;
vector<int> parent;
vector<int> num;
UnionFind(){}
UnionFind(int size){
this->size = size;
parent.resize(size+1);
num.resize(size+1);
init();
}
void init(){
for(int i = 0; i <= size; i++) parent[i] = i, num[i] = 1;
}
int root(int i){
if(parent[i] == i) return i;
return parent[i] = root(parent[i]);
}
bool same(int i, int j){
return root(i) == root(j);
}
void unite(int i, int j){
int root_i = root(i), root_j = root(j);
if(root_i == root_j) return;
num[root_j] += num[root_i];
parent[root_i] = root_j;
}
};
llint n, m, Q;
string s[100005];
vector<llint> G[100005];
UnionFind uf(1000005);
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> Q;
for(int i = 1; i <= n; i++) cin >> s[i];
llint u, v;
for(int i = 1; i <= m; i++){
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
for(int i = 0; i < 7; i++){
if(s[u][i]%2 && s[v][i]%2) uf.unite(i*n+u, i*n+v);
}
}
for(int i = 1; i <= n; i++){
for(int j = 0; j < 7; j++){
if(s[i][j]%2 && s[i][(j+1)%7]%2) uf.unite(j*n+i, (j+1)%7*n+i);
}
}
llint t, x, y;
for(int q = 0; q < Q; q++){
cin >> t >> x >> y;
y--;
if(t == 1){
s[x][y] = '1';
for(int j = 0; j < 7; j++){
if(s[x][j]%2 && s[x][(j+1)%7]%2) uf.unite(j*n+x, (j+1)%7*n+x);
}
for(int i = 0; i < G[x].size(); i++){
llint nx = G[x][i];
if(s[nx][y]%2) uf.unite(y*n+x, y*n+nx);
}
}
else cout << uf.num[uf.root(x)] << endl;
}
return 0;
}
leaf_1415