結果

問題 No.1266 7 Colors
ユーザー kotatsugamekotatsugame
提出日時 2020-10-24 01:37:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,339 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 71,496 KB
実行使用メモリ 15,888 KB
最終ジャッジ日時 2023-09-28 19:58:25
合計ジャッジ時間 6,624 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,540 KB
testcase_01 AC 5 ms
10,592 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 255 ms
15,888 KB
testcase_19 AC 146 ms
15,824 KB
testcase_20 AC 145 ms
15,720 KB
testcase_21 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<vector>
using namespace std;
#line 2 "/home/kotatsugame/library/datastructure/UF.cpp"
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
#line 5 "a.cpp"
int N,M,Q;
string s[1<<17];
vector<int>G[1<<17];
main()
{
	cin>>N>>M>>Q;
	UF uf(N*7);
	for(int i=0;i<N;i++)
	{
		cin>>s[i];
		for(int j=0;j<7;j++)
		{
			if(s[i][j]=='1'&&s[i][(j+1)%7]=='1')
			{
				uf.unite(i*7+j,i*7+(j+1)%7);
			}
		}
	}
	for(int i=0;i<M;i++)
	{
		int u,v;cin>>u>>v;
		u--,v--;
		for(int j=0;j<7;j++)if(s[u][j]=='1'&&s[v][j]=='1')
		{
			uf.unite(u*7+j,v*7+j);
		}
	}
	for(;Q--;)
	{
		int q,u,c;cin>>q>>u>>c;
		u--;
		if(q==1)
		{
			c--;
			s[u][c]='1';
			if(s[u][(c+6)%7]=='1')uf.unite(u*7+c,u*7+(c+6)%7);
			if(s[u][(c+1)%7]=='1')uf.unite(u*7+c,u*7+(c+1)%7);
			for(int v:G[u])if(s[v][c]=='1')uf.unite(u*7+c,v*7+c);
		}
		else
		{
			cout<<uf.size(u*7)<<endl;
		}
	}
}
0