結果

問題 No.2290 UnUnion Find
ユーザー RamurataRamurata
提出日時 2023-05-05 22:39:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,990 bytes
コンパイル時間 4,797 ms
コンパイル使用メモリ 265,624 KB
実行使用メモリ 12,684 KB
最終ジャッジ日時 2024-05-02 17:36:25
合計ジャッジ時間 10,250 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 608 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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; cin >> n >> q;
    dsu uni(n);
    rep(qi, q) {
        int t; cin >> t;
        if(t == 1) {
            int u, v; cin >> u >> v;
            uni.merge(u-1,v-1);
        } else {
            int v; cin >> v;
            v--;
            if(uni.groups().size() == 1) {
                cout << -1 << endl;
            } else {
                for(auto x : uni.groups()) {
                    if(!uni.same(x[0], v)) {
                        cout << x[0] + 1 << endl;
                        break;
                    }
                }
            }
        }
    }
}
0