結果

問題 No.1266 7 Colors
ユーザー leaf_1415leaf_1415
提出日時 2020-10-23 22:30:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 306 ms / 3,000 ms
コード長 2,075 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 83,800 KB
実行使用メモリ 21,672 KB
最終ジャッジ日時 2023-09-28 16:36:23
合計ジャッジ時間 7,798 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
16,104 KB
testcase_01 AC 11 ms
16,348 KB
testcase_02 AC 11 ms
16,100 KB
testcase_03 AC 204 ms
19,300 KB
testcase_04 AC 280 ms
19,732 KB
testcase_05 AC 216 ms
19,092 KB
testcase_06 AC 299 ms
19,800 KB
testcase_07 AC 306 ms
19,720 KB
testcase_08 AC 291 ms
19,728 KB
testcase_09 AC 267 ms
19,528 KB
testcase_10 AC 255 ms
19,480 KB
testcase_11 AC 227 ms
19,264 KB
testcase_12 AC 229 ms
19,204 KB
testcase_13 AC 239 ms
19,520 KB
testcase_14 AC 213 ms
19,100 KB
testcase_15 AC 298 ms
19,804 KB
testcase_16 AC 231 ms
19,200 KB
testcase_17 AC 296 ms
19,832 KB
testcase_18 AC 197 ms
21,672 KB
testcase_19 AC 80 ms
21,064 KB
testcase_20 AC 80 ms
21,064 KB
testcase_21 AC 173 ms
18,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0