結果

問題 No.2290 UnUnion Find
ユーザー Ecrade_Ecrade_
提出日時 2023-05-05 21:26:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,249 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 173,512 KB
実行使用メモリ 14,432 KB
最終ジャッジ日時 2023-08-15 02:53:07
合計ジャッジ時間 11,486 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 11 ms
4,380 KB
testcase_03 AC 79 ms
8,968 KB
testcase_04 AC 90 ms
8,956 KB
testcase_05 AC 85 ms
8,948 KB
testcase_06 AC 84 ms
9,020 KB
testcase_07 AC 84 ms
9,144 KB
testcase_08 AC 85 ms
9,104 KB
testcase_09 AC 89 ms
9,076 KB
testcase_10 AC 87 ms
8,948 KB
testcase_11 AC 92 ms
8,956 KB
testcase_12 AC 93 ms
9,160 KB
testcase_13 AC 93 ms
9,012 KB
testcase_14 AC 90 ms
8,960 KB
testcase_15 AC 85 ms
9,008 KB
testcase_16 AC 88 ms
9,016 KB
testcase_17 AC 91 ms
8,952 KB
testcase_18 AC 86 ms
8,960 KB
testcase_19 AC 109 ms
9,760 KB
testcase_20 AC 160 ms
14,420 KB
testcase_21 AC 21 ms
4,380 KB
testcase_22 AC 55 ms
6,288 KB
testcase_23 AC 55 ms
6,468 KB
testcase_24 AC 135 ms
11,524 KB
testcase_25 AC 45 ms
5,536 KB
testcase_26 AC 151 ms
13,080 KB
testcase_27 AC 143 ms
12,108 KB
testcase_28 AC 80 ms
8,140 KB
testcase_29 AC 126 ms
11,204 KB
testcase_30 AC 27 ms
4,436 KB
testcase_31 AC 119 ms
10,340 KB
testcase_32 AC 48 ms
5,688 KB
testcase_33 AC 79 ms
7,928 KB
testcase_34 AC 165 ms
14,432 KB
testcase_35 AC 144 ms
12,892 KB
testcase_36 AC 52 ms
5,808 KB
testcase_37 AC 75 ms
7,324 KB
testcase_38 AC 50 ms
5,816 KB
testcase_39 AC 58 ms
6,420 KB
testcase_40 AC 140 ms
12,432 KB
testcase_41 AC 43 ms
5,444 KB
testcase_42 AC 110 ms
9,412 KB
testcase_43 AC 100 ms
9,268 KB
testcase_44 AC 85 ms
8,992 KB
testcase_45 AC 86 ms
8,956 KB
testcase_46 AC 85 ms
8,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll t = 1,n,m,k,q,l,r,a,b,c,u,v,x,y,z,id[200009],o;
string s;
struct st{ll x,y; /*bool operator < (const st &a) const{return x < a.x;};*/};
bool cmp(const st &a,const st &b){return a.x < b.x;}
inline ll read(){
	ll s = 0,w = 1;
	char ch = getchar();
	while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();}
	while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar();
	return s * w;
}
ll qp(ll x,ll y){
	ll a = 1,b = x;
	while (y){
		if (y & 1) a = a * b % mod;
		b = b * b % mod,y >>= 1;
	}
	return a;
}
ll find(ll x){return x == id[x] ? x : id[x] = find(id[x]);}
int main(){//t = read();
while (t --){
	set <ll> s;
	n = read(),q = read();
	for (ll i = 1;i <= n;i += 1) id[i] = i,s.insert(i);
	for (ll i = 1;i <= q;i += 1){
		o = read();
		if (o == 1){
			x = read(),y = read();
			ll qwq = find(x),awa = find(y);
			if (qwq == awa) continue;
			s.erase(awa),id[awa] = qwq;
		}
		else{
			x = read();
			if (s.size() == 1) puts("-1");
			else{
				ll qwq = *s.begin();
				if (find(qwq) == find(x)){
					ll awa = *(++ s.begin());
					printf("%lld\n",awa);
				}
				else printf("%lld\n",qwq);
			}
		}
	}
}
	return 0;
}
0