結果

問題 No.2290 UnUnion Find
ユーザー achapiachapi
提出日時 2023-05-05 22:16:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 692 bytes
コンパイル時間 4,612 ms
コンパイル使用メモリ 267,396 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-05-02 16:49:53
合計ジャッジ時間 28,154 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 351 ms
5,376 KB
testcase_03 AC 386 ms
8,320 KB
testcase_04 AC 387 ms
8,448 KB
testcase_05 AC 393 ms
8,320 KB
testcase_06 AC 384 ms
8,448 KB
testcase_07 AC 383 ms
8,320 KB
testcase_08 AC 383 ms
8,320 KB
testcase_09 AC 390 ms
8,320 KB
testcase_10 AC 384 ms
8,448 KB
testcase_11 AC 389 ms
8,320 KB
testcase_12 AC 386 ms
8,320 KB
testcase_13 AC 388 ms
8,320 KB
testcase_14 AC 390 ms
8,320 KB
testcase_15 AC 386 ms
8,448 KB
testcase_16 AC 386 ms
8,320 KB
testcase_17 AC 388 ms
8,320 KB
testcase_18 AC 390 ms
8,320 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 516 ms
10,624 KB
testcase_25 WA -
testcase_26 AC 540 ms
12,032 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 502 ms
10,112 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 556 ms
13,312 KB
testcase_35 AC 535 ms
11,904 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 538 ms
11,520 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 393 ms
8,320 KB
testcase_45 AC 425 ms
8,448 KB
testcase_46 AC 420 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

int main() {
	int n, q;
	cin >> n >> q;
	atcoder::dsu uf(n);
	multiset<int> s;
	for (int i = 0; i < n; i++){
		s.insert(i);
	}
	while (q--){
		int t;
		cin >> t;
		if (t == 1){
			int u, v;
			cin >> u >> v;
			u--;
			v--;
			s.erase(s.find(uf.leader(u)));
			s.erase(s.find(uf.leader(v)));
			uf.merge(u, v);
			s.insert(uf.leader(u));
			s.insert(uf.leader(v));
		} else {
			int u;
			cin >> u;
			u--;
			if (*s.begin() != uf.leader(u)){
				cout << (*s.begin()) + 1 << endl;
			} else if ((*prev(s.end())) != uf.leader(u)) {
				cout << (*prev(s.end())) + 1 << endl;
			} else {
				cout << -1 << endl;
			}
		}
	}
}
0