結果

問題 No.2290 UnUnion Find
ユーザー kwm_tkwm_t
提出日時 2023-05-05 21:29:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 1,413 bytes
コンパイル時間 4,531 ms
コンパイル使用メモリ 266,320 KB
実行使用メモリ 13,580 KB
最終ジャッジ日時 2023-08-15 03:01:46
合計ジャッジ時間 16,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 39 ms
4,376 KB
testcase_03 AC 129 ms
8,084 KB
testcase_04 AC 133 ms
8,092 KB
testcase_05 AC 131 ms
8,244 KB
testcase_06 AC 136 ms
8,108 KB
testcase_07 AC 126 ms
8,236 KB
testcase_08 AC 130 ms
8,120 KB
testcase_09 AC 126 ms
8,104 KB
testcase_10 AC 132 ms
8,140 KB
testcase_11 AC 134 ms
8,088 KB
testcase_12 AC 128 ms
8,096 KB
testcase_13 AC 130 ms
8,164 KB
testcase_14 AC 127 ms
8,096 KB
testcase_15 AC 134 ms
8,172 KB
testcase_16 AC 132 ms
8,124 KB
testcase_17 AC 138 ms
8,108 KB
testcase_18 AC 134 ms
8,124 KB
testcase_19 AC 195 ms
8,904 KB
testcase_20 AC 297 ms
13,376 KB
testcase_21 AC 47 ms
4,380 KB
testcase_22 AC 90 ms
5,828 KB
testcase_23 AC 92 ms
5,812 KB
testcase_24 AC 232 ms
10,484 KB
testcase_25 AC 75 ms
5,296 KB
testcase_26 AC 276 ms
12,260 KB
testcase_27 AC 258 ms
11,068 KB
testcase_28 AC 134 ms
7,288 KB
testcase_29 AC 225 ms
9,888 KB
testcase_30 AC 54 ms
4,440 KB
testcase_31 AC 197 ms
9,484 KB
testcase_32 AC 78 ms
5,252 KB
testcase_33 AC 136 ms
7,400 KB
testcase_34 AC 271 ms
13,580 KB
testcase_35 AC 257 ms
11,740 KB
testcase_36 AC 83 ms
5,440 KB
testcase_37 AC 120 ms
6,680 KB
testcase_38 AC 83 ms
5,376 KB
testcase_39 AC 98 ms
5,936 KB
testcase_40 AC 262 ms
11,208 KB
testcase_41 AC 73 ms
4,960 KB
testcase_42 AC 172 ms
8,620 KB
testcase_43 AC 166 ms
8,356 KB
testcase_44 AC 127 ms
8,300 KB
testcase_45 AC 137 ms
8,244 KB
testcase_46 AC 144 ms
8,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q; cin >> n >> q;
	dsu uf(n);
	set<int>st;
	rep(i, n)st.insert(i);
	while (q--) {
		int t; cin >> t;
		if (1 == t) {
			int u, v; cin >> u >> v;
			u--, v--;
			st.erase(uf.leader(u));
			st.erase(uf.leader(v));
			uf.merge(u, v);
			st.insert(uf.leader(u));
		}
		else {
			int u; cin >> u, u--;
			u = uf.leader(u);
			if (1 == st.size())cout << -1 << endl;
			else {
				for (auto e : st) {
					if (e == u)continue;
					else {
						cout << e + 1 << endl;
						break;
					}
				}
			}
		}
	}
	return 0;
}
0