結果
問題 | No.2290 UnUnion Find |
ユーザー |
|
提出日時 | 2023-05-05 21:46:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 562 bytes |
コンパイル時間 | 3,700 ms |
コンパイル使用メモリ | 251,584 KB |
最終ジャッジ日時 | 2025-02-12 17:54:55 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 20 WA * 26 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;int main() {int n, q;cin >> n >> q;atcoder::dsu uf(n);while (q--){int t;cin >> t;if (t == 1){int u, v;cin >> u >> v;u--;v--;uf.merge(u, v);} else {int u;cin >> u;u--;if (uf.size(u) == n){cout << -1 << endl;} else {int l = 0, r = n;while (r - l > 1){int mid = (l + r) / 2;if (uf.leader(mid) != uf.leader(u)){l = mid;} else {r = mid;}}cout << l + 1 << endl;}}}}