結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 351 ms
8,320 KB
testcase_04 AC 349 ms
8,320 KB
testcase_05 AC 358 ms
8,448 KB
testcase_06 AC 351 ms
8,320 KB
testcase_07 AC 357 ms
8,448 KB
testcase_08 AC 348 ms
8,320 KB
testcase_09 AC 356 ms
8,320 KB
testcase_10 AC 356 ms
8,192 KB
testcase_11 AC 354 ms
8,448 KB
testcase_12 AC 356 ms
8,448 KB
testcase_13 AC 352 ms
8,320 KB
testcase_14 AC 354 ms
8,320 KB
testcase_15 AC 357 ms
8,448 KB
testcase_16 AC 353 ms
8,320 KB
testcase_17 AC 352 ms
8,320 KB
testcase_18 AC 356 ms
8,320 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 470 ms
10,752 KB
testcase_25 WA -
testcase_26 AC 497 ms
12,032 KB
testcase_27 AC 487 ms
11,392 KB
testcase_28 WA -
testcase_29 AC 467 ms
10,112 KB
testcase_30 WA -
testcase_31 AC 452 ms
9,600 KB
testcase_32 WA -
testcase_33 AC 406 ms
7,424 KB
testcase_34 AC 518 ms
13,312 KB
testcase_35 AC 506 ms
11,904 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 496 ms
11,392 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 352 ms
8,320 KB
testcase_45 AC 362 ms
8,320 KB
testcase_46 AC 377 ms
8,320 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.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