結果

問題 No.2290 UnUnion Find
ユーザー kotatsugamekotatsugame
提出日時 2023-05-05 21:24:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2023-08-15 02:45:41
合計ジャッジ時間 12,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 39 ms
4,380 KB
testcase_03 AC 134 ms
8,152 KB
testcase_04 AC 130 ms
8,072 KB
testcase_05 AC 124 ms
8,056 KB
testcase_06 AC 127 ms
8,072 KB
testcase_07 AC 124 ms
8,056 KB
testcase_08 AC 127 ms
8,080 KB
testcase_09 AC 127 ms
8,152 KB
testcase_10 AC 128 ms
8,064 KB
testcase_11 AC 130 ms
8,068 KB
testcase_12 AC 128 ms
8,128 KB
testcase_13 AC 127 ms
8,348 KB
testcase_14 AC 131 ms
8,172 KB
testcase_15 AC 127 ms
8,084 KB
testcase_16 AC 129 ms
8,064 KB
testcase_17 AC 135 ms
8,084 KB
testcase_18 AC 134 ms
8,068 KB
testcase_19 AC 173 ms
8,864 KB
testcase_20 AC 268 ms
13,568 KB
testcase_21 AC 47 ms
4,380 KB
testcase_22 AC 91 ms
5,736 KB
testcase_23 AC 90 ms
5,804 KB
testcase_24 AC 232 ms
10,492 KB
testcase_25 AC 73 ms
5,112 KB
testcase_26 AC 254 ms
11,960 KB
testcase_27 AC 228 ms
10,924 KB
testcase_28 AC 135 ms
7,452 KB
testcase_29 AC 207 ms
9,968 KB
testcase_30 AC 54 ms
4,380 KB
testcase_31 AC 182 ms
9,444 KB
testcase_32 AC 76 ms
5,204 KB
testcase_33 AC 132 ms
7,216 KB
testcase_34 AC 257 ms
13,324 KB
testcase_35 AC 239 ms
11,760 KB
testcase_36 AC 81 ms
5,400 KB
testcase_37 AC 115 ms
6,820 KB
testcase_38 AC 79 ms
5,368 KB
testcase_39 AC 93 ms
5,904 KB
testcase_40 AC 229 ms
11,312 KB
testcase_41 AC 71 ms
5,136 KB
testcase_42 AC 166 ms
8,616 KB
testcase_43 AC 161 ms
8,340 KB
testcase_44 AC 129 ms
8,212 KB
testcase_45 AC 133 ms
8,148 KB
testcase_46 AC 130 ms
8,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<atcoder/dsu>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,Q;
	cin>>N>>Q;
	atcoder::dsu uf(N);
	set<int>S;
	for(int i=0;i<N;i++)S.insert(i);
	for(;Q--;)
	{
		int op;cin>>op;
		if(op==1)
		{
			int u,v;cin>>u>>v;u--,v--;
			if(!uf.same(u,v))
			{
				u=uf.leader(u);
				v=uf.leader(v);
				S.erase(u);
				S.erase(v);
				uf.merge(u,v);
				S.insert(uf.leader(u));
			}
		}
		else
		{
			int u;cin>>u;u--;
			u=uf.leader(u);
			int ans=-1;
			for(int v:S)if(u!=v)
			{
				ans=v+1;
				break;
			}
			cout<<ans<<"\n";
		}
	}
}
0