結果

問題 No.2290 UnUnion Find
ユーザー lgswdnlgswdn
提出日時 2023-05-06 20:41:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 207,448 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-05-03 04:47:35
合計ジャッジ時間 10,386 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 15 ms
5,376 KB
testcase_03 AC 74 ms
8,576 KB
testcase_04 AC 79 ms
8,832 KB
testcase_05 AC 78 ms
8,704 KB
testcase_06 AC 74 ms
8,576 KB
testcase_07 AC 76 ms
8,832 KB
testcase_08 AC 74 ms
8,704 KB
testcase_09 AC 76 ms
8,704 KB
testcase_10 AC 80 ms
8,704 KB
testcase_11 AC 76 ms
8,704 KB
testcase_12 AC 78 ms
8,704 KB
testcase_13 AC 75 ms
8,704 KB
testcase_14 AC 73 ms
8,704 KB
testcase_15 AC 75 ms
8,704 KB
testcase_16 AC 75 ms
8,576 KB
testcase_17 AC 79 ms
8,832 KB
testcase_18 AC 77 ms
8,832 KB
testcase_19 AC 90 ms
9,472 KB
testcase_20 AC 124 ms
13,696 KB
testcase_21 AC 20 ms
6,940 KB
testcase_22 AC 50 ms
6,940 KB
testcase_23 AC 49 ms
6,944 KB
testcase_24 AC 105 ms
11,008 KB
testcase_25 AC 40 ms
6,940 KB
testcase_26 AC 115 ms
12,416 KB
testcase_27 AC 113 ms
11,648 KB
testcase_28 AC 69 ms
7,808 KB
testcase_29 AC 97 ms
10,496 KB
testcase_30 AC 26 ms
6,940 KB
testcase_31 AC 93 ms
9,856 KB
testcase_32 AC 44 ms
6,940 KB
testcase_33 AC 68 ms
7,552 KB
testcase_34 AC 120 ms
13,696 KB
testcase_35 AC 114 ms
12,160 KB
testcase_36 AC 45 ms
6,940 KB
testcase_37 AC 61 ms
7,296 KB
testcase_38 AC 45 ms
5,760 KB
testcase_39 AC 51 ms
6,272 KB
testcase_40 AC 121 ms
11,776 KB
testcase_41 AC 40 ms
5,376 KB
testcase_42 AC 81 ms
9,088 KB
testcase_43 AC 79 ms
8,832 KB
testcase_44 AC 73 ms
8,704 KB
testcase_45 AC 71 ms
8,704 KB
testcase_46 AC 75 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef long double ld;

int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2e5+9;
int id[N],n,m;
set<int>s;

int find(int x) {return x==id[x]?x:id[x]=find(id[x]);}

signed main() {
  n=read(), m=read();
  rep(i,1,n) id[i]=i, s.insert(i);
  rep(i,1,m) {
    int op=read();
    if(op==1) {
      int x=read(), y=read();
      x=find(x), y=find(y);
      id[y]=x, s.erase(y);
    } else {
      int x=read(); x=find(x);
      if(s.size()==1) puts("-1");
      else {
        auto it=s.begin();
        if((*it)==x) ++it;
        printf("%d\n",*it);
      }
    }
  }
  return 0;
}
0