結果

問題 No.2290 UnUnion Find
ユーザー RamurataRamurata
提出日時 2023-05-06 11:40:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 3,096 bytes
コンパイル時間 4,566 ms
コンパイル使用メモリ 269,916 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-05-03 00:55:37
合計ジャッジ時間 23,324 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 311 ms
5,376 KB
testcase_03 AC 318 ms
8,448 KB
testcase_04 AC 310 ms
8,448 KB
testcase_05 AC 318 ms
8,320 KB
testcase_06 AC 299 ms
8,448 KB
testcase_07 AC 298 ms
8,320 KB
testcase_08 AC 302 ms
8,448 KB
testcase_09 AC 291 ms
8,448 KB
testcase_10 AC 314 ms
8,476 KB
testcase_11 AC 289 ms
8,448 KB
testcase_12 AC 311 ms
8,448 KB
testcase_13 AC 302 ms
8,320 KB
testcase_14 AC 300 ms
8,320 KB
testcase_15 AC 302 ms
8,448 KB
testcase_16 AC 302 ms
8,448 KB
testcase_17 AC 306 ms
8,320 KB
testcase_18 AC 297 ms
8,448 KB
testcase_19 AC 336 ms
9,216 KB
testcase_20 AC 404 ms
13,568 KB
testcase_21 AC 320 ms
5,376 KB
testcase_22 AC 311 ms
5,876 KB
testcase_23 AC 319 ms
5,888 KB
testcase_24 AC 371 ms
10,752 KB
testcase_25 AC 322 ms
5,376 KB
testcase_26 AC 425 ms
12,160 KB
testcase_27 AC 381 ms
11,264 KB
testcase_28 AC 327 ms
7,424 KB
testcase_29 AC 361 ms
10,240 KB
testcase_30 AC 323 ms
5,376 KB
testcase_31 AC 404 ms
9,472 KB
testcase_32 AC 356 ms
5,376 KB
testcase_33 AC 354 ms
7,320 KB
testcase_34 AC 399 ms
13,440 KB
testcase_35 AC 404 ms
12,032 KB
testcase_36 AC 312 ms
5,632 KB
testcase_37 AC 337 ms
6,912 KB
testcase_38 AC 321 ms
5,480 KB
testcase_39 AC 309 ms
6,272 KB
testcase_40 AC 394 ms
11,520 KB
testcase_41 AC 313 ms
5,376 KB
testcase_42 AC 342 ms
8,832 KB
testcase_43 AC 372 ms
8,576 KB
testcase_44 AC 294 ms
8,320 KB
testcase_45 AC 320 ms
8,320 KB
testcase_46 AC 309 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/2P/Desktop/ramstream/library/template/template.hpp"
/**
 * @brief Header
 */
#include <bits/stdc++.h>
// #include <algorithm>
// #include <cmath>
// #include <complex>
// #include <cstdio>
// #include <iostream>
// #include <map>
// #include <numeric>
// #include <queue>
// #include <set>
// #include <stack>
// #include <string>
// #include <vector>
// #include <climits>
// #include <deque>
// #include <iomanip>
// #include <limits>
using namespace std;
typedef long long ll;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(i, n) for (int i = 0; i < int(n); ++i)
#define rep2(i, s, n) for (int i = int(s); i < int(n); ++i)
#define rep3(i, s, n, d) for(int i = int(s); i < int(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fir first
#define sec second
#define pb push_back
#define em emplace_back
#define mk make_pair
#define SUM(a) accumulate(all(a),0LL)
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
template<class... T> void input(T&... a){(cin >> ... >> a);}
#define INT(...) int __VA_ARGS__;input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;input(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;input(__VA_ARGS__)
void Yes(bool iSizIs=true) {if(iSizIs){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void No() {cout<<"No"<<endl;}
template<class T> void OUT(T x) {cout << (x) << endl;}
template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}return false;}
ll POW(ll a, ll n, ll mod) {
    if (n == 0) return 1;
    if (n == 1) return a % mod;
    ll ret = POW(a, n / 2, mod) % mod;
    (ret *= ret) %= mod;
    if (n % 2 == 1) {
        (ret *= a) %= mod;
    }
    return ret;
}
const int inf = INT_MAX / 2; 
const ll infl = 1LL << 60;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
#include <atcoder/all>
using namespace atcoder;
#line 2 "sol.cpp"

int main() {
    INT(n, q);
    dsu uni(n);
    set<int> s;
    rep(i, n) s.insert(i);
    rep(qi, q) {
        int t; cin >> t;
        if(t == 1) {
            INT(u, v);
            u--, v--;
            s.erase(uni.leader(u));
            s.erase(uni.leader(v));
            uni.merge(u, v);
            s.insert(uni.leader(u));
        } else {
            INT(v);
            v--;
            if(s.size() == 1) {
                cout << -1 << endl;
            } else {
                for(auto x : s) {
                    if(!uni.same(x, v)) {
                        cout << x + 1 << endl;
                        break;
                    }
                }
            }
        }
    }
}
0