結果

問題 No.2290 UnUnion Find
ユーザー kabipoyokabipoyo
提出日時 2023-05-05 23:19:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 549 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 4,654 ms
コンパイル使用メモリ 269,008 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-05-02 18:33:01
合計ジャッジ時間 28,205 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 341 ms
5,376 KB
testcase_03 AC 366 ms
8,320 KB
testcase_04 AC 361 ms
8,320 KB
testcase_05 AC 372 ms
8,320 KB
testcase_06 AC 371 ms
8,320 KB
testcase_07 AC 360 ms
8,320 KB
testcase_08 AC 356 ms
8,320 KB
testcase_09 AC 361 ms
8,320 KB
testcase_10 AC 357 ms
8,320 KB
testcase_11 AC 360 ms
8,320 KB
testcase_12 AC 353 ms
8,192 KB
testcase_13 AC 373 ms
8,448 KB
testcase_14 AC 357 ms
8,320 KB
testcase_15 AC 359 ms
8,320 KB
testcase_16 AC 356 ms
8,448 KB
testcase_17 AC 357 ms
8,320 KB
testcase_18 AC 362 ms
8,448 KB
testcase_19 AC 451 ms
9,088 KB
testcase_20 AC 549 ms
13,312 KB
testcase_21 AC 347 ms
5,376 KB
testcase_22 AC 372 ms
5,888 KB
testcase_23 AC 367 ms
5,760 KB
testcase_24 AC 489 ms
10,752 KB
testcase_25 AC 362 ms
5,376 KB
testcase_26 AC 502 ms
11,904 KB
testcase_27 AC 499 ms
11,136 KB
testcase_28 AC 403 ms
7,424 KB
testcase_29 AC 486 ms
10,240 KB
testcase_30 AC 347 ms
5,376 KB
testcase_31 AC 458 ms
9,472 KB
testcase_32 AC 366 ms
5,376 KB
testcase_33 AC 412 ms
7,188 KB
testcase_34 AC 529 ms
13,312 KB
testcase_35 AC 508 ms
12,032 KB
testcase_36 AC 373 ms
5,504 KB
testcase_37 AC 397 ms
6,812 KB
testcase_38 AC 366 ms
5,376 KB
testcase_39 AC 380 ms
6,144 KB
testcase_40 AC 516 ms
11,392 KB
testcase_41 AC 359 ms
5,376 KB
testcase_42 AC 434 ms
8,704 KB
testcase_43 AC 435 ms
8,448 KB
testcase_44 AC 352 ms
8,192 KB
testcase_45 AC 378 ms
8,320 KB
testcase_46 AC 406 ms
8,448 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