結果

問題 No.2290 UnUnion Find
ユーザー cyk203cyk203
提出日時 2023-05-05 21:27:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 2,997 bytes
コンパイル時間 1,836 ms
コンパイル使用メモリ 173,548 KB
実行使用メモリ 16,528 KB
最終ジャッジ日時 2023-08-15 02:56:07
合計ジャッジ時間 10,315 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 11 ms
4,412 KB
testcase_03 AC 70 ms
10,872 KB
testcase_04 AC 78 ms
11,692 KB
testcase_05 AC 78 ms
11,704 KB
testcase_06 AC 79 ms
11,992 KB
testcase_07 AC 80 ms
11,456 KB
testcase_08 AC 81 ms
11,836 KB
testcase_09 AC 79 ms
11,292 KB
testcase_10 AC 80 ms
11,584 KB
testcase_11 AC 78 ms
11,900 KB
testcase_12 AC 79 ms
11,624 KB
testcase_13 AC 78 ms
11,660 KB
testcase_14 AC 79 ms
11,924 KB
testcase_15 AC 79 ms
11,984 KB
testcase_16 AC 77 ms
11,732 KB
testcase_17 AC 79 ms
12,140 KB
testcase_18 AC 80 ms
11,976 KB
testcase_19 AC 92 ms
11,900 KB
testcase_20 AC 134 ms
16,528 KB
testcase_21 AC 18 ms
5,404 KB
testcase_22 AC 51 ms
8,080 KB
testcase_23 AC 51 ms
8,212 KB
testcase_24 AC 114 ms
13,576 KB
testcase_25 AC 43 ms
7,124 KB
testcase_26 AC 126 ms
15,056 KB
testcase_27 AC 115 ms
14,148 KB
testcase_28 AC 73 ms
10,020 KB
testcase_29 AC 105 ms
12,988 KB
testcase_30 AC 24 ms
5,852 KB
testcase_31 AC 99 ms
12,244 KB
testcase_32 AC 44 ms
7,332 KB
testcase_33 AC 75 ms
9,872 KB
testcase_34 AC 135 ms
16,464 KB
testcase_35 AC 123 ms
15,016 KB
testcase_36 AC 47 ms
7,744 KB
testcase_37 AC 65 ms
9,248 KB
testcase_38 AC 45 ms
7,472 KB
testcase_39 AC 54 ms
8,240 KB
testcase_40 AC 118 ms
14,396 KB
testcase_41 AC 41 ms
6,988 KB
testcase_42 AC 90 ms
11,484 KB
testcase_43 AC 85 ms
11,176 KB
testcase_44 AC 79 ms
11,832 KB
testcase_45 AC 74 ms
10,996 KB
testcase_46 AC 84 ms
11,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* 
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
#define re(i,a,b) for(ll i=(a);i<(b);i++)
#define pe(i,a,b) for(ll i=(a);i>(b);i--)
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline void read(T& r) {
	r=0;bool w=0; char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
	r=w?-r:r;
}
template <typename T>
inline void readupp(T& r){
	r=0;
	char ch=getchar();
	while(ch>'Z'||ch<'A')ch=getchar();
	r=ch;
}
template <typename T>
inline void readlow(T& r){
	r=0;
	char ch=getchar();
	while(ch>'z'||ch<'a')ch=getchar();
	r=ch;
}
template <typename T>
inline void readdig(T& r){
	r=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	r=ch-'0';
}
template <typename T>
inline void readvisi(T& r){
	r=0;
	char ch=getchar();
	while(ch>126||ch<33)ch=getchar();
	r=ch;
}
template <typename T>
inline ll readlowstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'z'||ch<'a')ch=getchar();
	while(ch<='z'&&ch>='a')r[++n]=ch-'a',ch=getchar();
	return n;
}
template <typename T>
inline ll readuppstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'Z'||ch<'A')ch=getchar();
	while(ch<='Z'&&ch>='A')r[++n]=ch-'A',ch=getchar();
	return n;
}
template <typename T>
inline ll readdigstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch<='9'&&ch>='0')r[++n]=ch-'0',ch=getchar();
	return n;
}
template <typename T>
inline ll readvisistr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>126||ch<33)ch=getchar();
	while(ch<=126&&ch>=33)r[++n]=ch,ch=getchar();
	return n;
}
const ll MOD=998244353;
ll gcd(ll A,ll B){return B?gcd(B,A%B):A;}
template<typename T>
void chkmax(T&A,T B){if(A<B)A=B;}
template<typename T>
void chkmin(T&A,T B){if(A>B)A=B;}
template<typename T>
T Madd(T A,T B){return A+B>=MOD?A+B-MOD:A+B;}
template<typename T>
T Msub(T A,T B){return A-B<0?A-B+MOD:A-B;}
template<typename T>
void MODed(T &A){A%=MOD;A+=(A<0?MOD:0);}
ll pw(ll A,ll B){
	ll res=1;
	while(B){
		if(B&1)res=res*A%MOD;
		A=A*A%MOD;
		B>>=1;
	}
	return res;
}
void _FILE(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
const ll N=200003,M=3003,INF=2000000000000000007ll;
ll n,q,id[N];
ll find(ll x){return x==id[x]?x:id[x]=find(id[x]);}
void unite(ll x,ll y){id[find(x)]=find(y);}
set<ll> s;
int main(){
	read(n);
	rep(i,1,n)id[i]=i;
	read(q);
	rep(i,1,n)s.insert(i);
	rep(i,1,q){
		ll in1,in2,in3;
		read(in1);
		if(in1==1){
			read(in2),read(in3);
			if(find(in2)!=find(in3)){
				s.erase(find(in2));
				id[find(in2)]=find(in3);
			}
		}
		else{
			read(in2);
			if(s.size()==1)puts("-1");
			else if((*s.begin())!=find(in2))printf("%lld\n",*s.begin());
			else printf("%lld\n",*s.rbegin());
		}
	}
	return 0;
}
0