結果

問題 No.2290 UnUnion Find
ユーザー Taiki0715Taiki0715
提出日時 2023-05-05 21:53:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,010 bytes
コンパイル時間 4,264 ms
コンパイル使用メモリ 163,564 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-05-02 16:04:16
合計ジャッジ時間 22,681 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 319 ms
15,104 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 297 ms
12,160 KB
testcase_25 WA -
testcase_26 AC 298 ms
13,568 KB
testcase_27 AC 303 ms
12,800 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 300 ms
11,008 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 331 ms
15,104 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 306 ms
13,056 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 291 ms
9,472 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cassert>
#include <bitset>
#include <map>
#include <algorithm>
#include <iterator>
#include <string>
#include <utility>
#include <numeric>
#include <regex>
#include <complex>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
  os<<p.first<<" "<<p.second;
  return os;
}
template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
  is>>p.first>>p.second;
  return is;
}
template<typename T>
istream &operator>>(istream &is,vector<T> &a){
  for(auto &i:a)is>>i;
  return is;
}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
ll myceil(ll a,ll b){return (a+b-1)/b;}
int main(){
  int n,q;
  cin>>n>>q;
  vector<vector<int>>id(n);
  rep(i,n)id[i].push_back(i);
  dsu uf(n);
  while(q--){
    int t;
    cin>>t;
    if(t==1){
      int u,v;
      cin>>u>>v;
      u--,v--;
      int lu=uf.leader(u),lv=uf.leader(v);
      uf.merge(u,v);
      int l=uf.leader(u);
      if(l!=lu)swap(lu,lv);
      vector<int>nxt;
      std::merge(all(id[u]),all(id[v]),back_inserter(nxt));
      swap(id[u],nxt);
    }
    else{
      int u;
      cin>>u;
      u--;
      if(id[u].size()==n){
        cout<<-1<<endl;
        continue;
      }
      if(!binary_search(all(id[u]),n-1)){
        cout<<n<<endl;
        continue;
      }
      int l=0,r=n;
      while(r-l>1){
        int mid=(l+r)/2;
        if(lower_bound(all(id[u]),mid)-id[u].begin()==mid)l=mid;
        else r=mid;
      }
      cout<<r<<endl;
    }
  }
}
0