結果

問題 No.2290 UnUnion Find
ユーザー kabipoyokabipoyo
提出日時 2023-05-05 23:19:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 4,588 ms
コンパイル使用メモリ 266,708 KB
実行使用メモリ 13,352 KB
最終ジャッジ日時 2023-08-15 06:31:52
合計ジャッジ時間 29,655 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 328 ms
4,384 KB
testcase_03 AC 341 ms
8,072 KB
testcase_04 AC 345 ms
8,096 KB
testcase_05 AC 351 ms
8,112 KB
testcase_06 AC 349 ms
8,112 KB
testcase_07 AC 345 ms
8,172 KB
testcase_08 AC 341 ms
8,152 KB
testcase_09 AC 346 ms
8,088 KB
testcase_10 AC 348 ms
8,176 KB
testcase_11 AC 346 ms
8,188 KB
testcase_12 AC 345 ms
8,100 KB
testcase_13 AC 339 ms
8,324 KB
testcase_14 AC 355 ms
8,112 KB
testcase_15 AC 343 ms
8,092 KB
testcase_16 AC 341 ms
8,108 KB
testcase_17 AC 344 ms
8,328 KB
testcase_18 AC 343 ms
8,192 KB
testcase_19 AC 427 ms
8,952 KB
testcase_20 AC 510 ms
13,352 KB
testcase_21 AC 340 ms
4,384 KB
testcase_22 AC 356 ms
5,888 KB
testcase_23 AC 348 ms
5,780 KB
testcase_24 AC 461 ms
10,468 KB
testcase_25 AC 350 ms
5,112 KB
testcase_26 AC 496 ms
12,056 KB
testcase_27 AC 479 ms
10,936 KB
testcase_28 AC 391 ms
7,548 KB
testcase_29 AC 454 ms
9,980 KB
testcase_30 AC 339 ms
4,380 KB
testcase_31 AC 433 ms
9,468 KB
testcase_32 AC 350 ms
5,308 KB
testcase_33 AC 386 ms
7,132 KB
testcase_34 AC 511 ms
13,092 KB
testcase_35 AC 495 ms
11,788 KB
testcase_36 AC 353 ms
5,336 KB
testcase_37 AC 375 ms
6,704 KB
testcase_38 AC 355 ms
5,320 KB
testcase_39 AC 361 ms
6,008 KB
testcase_40 AC 476 ms
11,384 KB
testcase_41 AC 349 ms
5,000 KB
testcase_42 AC 423 ms
8,544 KB
testcase_43 AC 413 ms
8,276 KB
testcase_44 AC 342 ms
8,172 KB
testcase_45 AC 356 ms
8,072 KB
testcase_46 AC 371 ms
8,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int main() {
	lint N, Q;
	cin >> N >> Q;

	lint a=0, b=0, c=0, x, y, z;
	set<lint> s;
	dsu d(N+1);
	rep(i, N) s.insert(i+1);
	rep(_, Q) {
		cin >> z;
		if (z == 1) {
			cin >> x >> y;
			s.erase(d.leader(x));
			s.erase(d.leader(y));
			d.merge(x, y);
			s.insert(d.leader(x));
		} else {
			cin >> x;
			y = d.leader(x);
			a = 0;
			for (auto t : s) {
				if (y != t) {
					cout << t << endl;
					a++;
					break;
				}
			}
			if (!a) cout << "-1" << endl;
		}
	}
}
0