結果
問題 |
No.2290 UnUnion Find
|
ユーザー |
|
提出日時 | 2023-05-05 21:57:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 689 bytes |
コンパイル時間 | 4,367 ms |
コンパイル使用メモリ | 257,052 KB |
最終ジャッジ日時 | 2025-02-12 18:08:09 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 27 WA * 19 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; int main() { int n, q; cin >> n >> q; atcoder::dsu uf(n); multiset<int> s; for (int i = 0; i < n; i++){ s.insert(i); } while (q--){ int t; cin >> t; if (t == 1){ int u, v; cin >> u >> v; u--; v--; s.erase(s.find(uf.leader(u))); s.erase(s.find(uf.leader(v))); uf.merge(u, v); s.insert(uf.leader(u)); s.insert(uf.leader(v)); } else { int u; cin >> u; u--; if (uf.size(u) == n){ cout << -1 << endl; } else { if (*s.begin() != uf.leader(u)){ cout << (*s.begin()) + 1 << endl; } else { cout << (*prev(s.end())) + 1 << endl; } } } } }