結果

問題 No.2290 UnUnion Find
ユーザー achapiachapi
提出日時 2023-05-05 21:46:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 562 bytes
コンパイル時間 4,627 ms
コンパイル使用メモリ 262,400 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 15:46:50
合計ジャッジ時間 22,234 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 354 ms
5,376 KB
testcase_03 AC 260 ms
5,376 KB
testcase_04 AC 263 ms
5,376 KB
testcase_05 AC 264 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 279 ms
5,376 KB
testcase_20 AC 281 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 323 ms
5,376 KB
testcase_24 AC 275 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 280 ms
5,376 KB
testcase_27 AC 277 ms
5,376 KB
testcase_28 AC 298 ms
5,376 KB
testcase_29 AC 284 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 285 ms
5,376 KB
testcase_32 WA -
testcase_33 AC 295 ms
5,376 KB
testcase_34 AC 288 ms
5,376 KB
testcase_35 AC 278 ms
5,376 KB
testcase_36 WA -
testcase_37 AC 306 ms
5,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 283 ms
5,376 KB
testcase_41 WA -
testcase_42 AC 282 ms
5,376 KB
testcase_43 AC 282 ms
5,376 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
	int n, q;
	cin >> n >> q;
	atcoder::dsu uf(n);
	while (q--){
		int t;
		cin >> t;
		if (t == 1){
			int u, v;
			cin >> u >> v;
			u--;
			v--;
			uf.merge(u, v);
		} else {
			int u;
			cin >> u;
			u--;
			if (uf.size(u) == n){
				cout << -1 << endl;
			} else {
				int l = 0, r = n;
				while (r - l > 1){
					int mid = (l + r) / 2;
					if (uf.leader(mid) != uf.leader(u)){
						l = mid;
					} else {
						r = mid;
					}
				}
				cout << l + 1 << endl;
			}
		}
	}
}
0