結果

問題 No.2290 UnUnion Find
ユーザー kabipoyokabipoyo
提出日時 2023-05-05 23:18:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,398 bytes
コンパイル時間 5,030 ms
コンパイル使用メモリ 268,996 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-05-02 18:28:14
合計ジャッジ時間 28,731 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 335 ms
5,376 KB
testcase_03 AC 361 ms
8,448 KB
testcase_04 AC 364 ms
8,320 KB
testcase_05 AC 371 ms
8,320 KB
testcase_06 AC 359 ms
8,320 KB
testcase_07 AC 362 ms
8,320 KB
testcase_08 AC 358 ms
8,320 KB
testcase_09 AC 367 ms
8,320 KB
testcase_10 AC 369 ms
8,320 KB
testcase_11 AC 369 ms
8,448 KB
testcase_12 AC 369 ms
8,320 KB
testcase_13 AC 363 ms
8,320 KB
testcase_14 AC 372 ms
8,448 KB
testcase_15 AC 361 ms
8,320 KB
testcase_16 AC 362 ms
8,320 KB
testcase_17 AC 370 ms
8,320 KB
testcase_18 AC 363 ms
8,320 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 513 ms
10,624 KB
testcase_25 WA -
testcase_26 AC 530 ms
12,032 KB
testcase_27 AC 519 ms
11,264 KB
testcase_28 WA -
testcase_29 AC 494 ms
9,984 KB
testcase_30 WA -
testcase_31 AC 472 ms
9,600 KB
testcase_32 WA -
testcase_33 AC 416 ms
7,424 KB
testcase_34 AC 566 ms
13,312 KB
testcase_35 AC 541 ms
11,904 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 523 ms
11,392 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 361 ms
8,320 KB
testcase_45 AC 389 ms
8,448 KB
testcase_46 AC 385 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;
			d.merge(x, y);
			s.erase(x);
			s.erase(y);
			s.erase(d.leader(x));
			s.erase(d.leader(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