結果

問題 No.2290 UnUnion Find
ユーザー Taiki0715Taiki0715
提出日時 2023-05-05 22:08:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,073 bytes
コンパイル時間 3,292 ms
コンパイル使用メモリ 164,352 KB
実行使用メモリ 15,160 KB
最終ジャッジ日時 2024-05-02 16:30:52
合計ジャッジ時間 8,609 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
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 #

#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--;
      if(uf.same(u,v))continue;
      u=uf.leader(u),v=uf.leader(v);
      uf.merge(u,v);
      int l=uf.leader(u);
      if(l!=u)swap(u,v);
      vector<int>nxt;
      std::merge(all(id[u]),all(id[v]),back_inserter(nxt));
      swap(id[u],nxt);
    }
    else{
      int u;
      cin>>u;
      u--;
      continue;
      u=uf.leader(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<<l+1<<endl;
    }
  }
}
0