結果

問題 No.2290 UnUnion Find
ユーザー ksukegamesksukegames
提出日時 2023-05-06 09:42:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 4,672 ms
コンパイル使用メモリ 309,992 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 23:36:09
合計ジャッジ時間 21,191 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 303 ms
5,248 KB
testcase_03 AC 224 ms
5,376 KB
testcase_04 AC 233 ms
5,376 KB
testcase_05 AC 232 ms
5,376 KB
testcase_06 AC 239 ms
5,376 KB
testcase_07 AC 229 ms
5,376 KB
testcase_08 AC 224 ms
5,376 KB
testcase_09 AC 237 ms
5,376 KB
testcase_10 AC 226 ms
5,376 KB
testcase_11 AC 232 ms
5,376 KB
testcase_12 AC 234 ms
5,376 KB
testcase_13 AC 238 ms
5,376 KB
testcase_14 AC 235 ms
5,376 KB
testcase_15 AC 227 ms
5,376 KB
testcase_16 AC 228 ms
5,376 KB
testcase_17 AC 225 ms
5,376 KB
testcase_18 AC 234 ms
5,376 KB
testcase_19 AC 241 ms
5,376 KB
testcase_20 AC 241 ms
5,376 KB
testcase_21 AC 332 ms
5,376 KB
testcase_22 AC 313 ms
5,376 KB
testcase_23 AC 282 ms
5,376 KB
testcase_24 AC 250 ms
5,376 KB
testcase_25 AC 293 ms
5,376 KB
testcase_26 AC 248 ms
5,376 KB
testcase_27 AC 235 ms
5,376 KB
testcase_28 AC 260 ms
5,376 KB
testcase_29 AC 236 ms
5,376 KB
testcase_30 AC 321 ms
5,376 KB
testcase_31 AC 237 ms
5,376 KB
testcase_32 AC 318 ms
5,376 KB
testcase_33 AC 265 ms
5,376 KB
testcase_34 AC 253 ms
5,376 KB
testcase_35 AC 238 ms
5,376 KB
testcase_36 AC 286 ms
5,376 KB
testcase_37 AC 260 ms
5,376 KB
testcase_38 AC 278 ms
5,376 KB
testcase_39 AC 275 ms
5,376 KB
testcase_40 AC 239 ms
5,376 KB
testcase_41 AC 292 ms
5,376 KB
testcase_42 AC 243 ms
5,376 KB
testcase_43 AC 274 ms
5,376 KB
testcase_44 AC 261 ms
5,376 KB
testcase_45 AC 236 ms
5,376 KB
testcase_46 AC 250 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)
#define coutf(f) cout << fixed << setprecision(f)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

int main() {
	int n, q;
	cin >> n >> q;
	dsu uf(n);
	int l = 0, r = n - 1;
	while (q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int u, v;
			cin >> u >> v;
			u--; v--;
			uf.merge(u, v);
			while (r != uf.leader(r)) r--;
			while (l != uf.leader(l)) l++;
		}
		else {
			int v;
			cin >> v;
			v--;
			cout << (l == r ? -1 : uf.same(l, v) ? r + 1 : l + 1) << endl;
		}
	}
	return 0;
}
0