結果
| 問題 | No.2290 UnUnion Find |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-05-06 21:36:08 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,101 bytes |
| 記録 | |
| コンパイル時間 | 1,366 ms |
| コンパイル使用メモリ | 186,700 KB |
| 実行使用メモリ | 23,952 KB |
| 最終ジャッジ日時 | 2026-05-06 21:36:27 |
| 合計ジャッジ時間 | 12,300 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std ;
#define int long long
const int N = 2e5 + 5 ;
int n , q , op , u , v , k , a[N] , fa[N] ;
set <int> st[N] ;
int find(int x)
{
if(fa[x] == x) return x ;
return fa[x] = find(fa[x]) ;
}
signed main()
{
ios::sync_with_stdio(0) ;
cin.tie(0) ;
cout.tie(0) ;
// freopen(".in" , "r" , stdin) ;
// freopen(".out" , "w" , stdout) ;
cin >> n >> q ;
for(int i = 1 ; i <= n ; i ++)
{
fa[i] = i ;
st[i].insert(i) ;
}
while(q --)
{
cin >> op ;
if(op == 1)
{
cin >> u >> v ;
int fu = find(u) , fv = find(v) ;
if(fu == fv) continue ;
if(st[fu].size() > st[fv].size()) swap(st[fu] , st[fv]) ;
for(auto i : st[fu]) st[fv].insert(i) ;
st[fu].clear() ;
fa[fu] = fv ;
}
if(op == 2)
{
cin >> v >> k ;
int fv = find(v) ;
if(st[fv].size() < k)
{
cout << -1 << "\n" ;
continue ;
}
auto it = st[fv].end() ;
for(int i = 1 ; i <= k ; i ++) it -- ;
cout << (*it) << "\n" ;
}
}
return 0 ;
}
/**
* @runId: 63562
* @language: C++ With O2
* @author: ???
* @submitTime: 2026-05-06 15:54:28
*/
vjudge1