結果
| 問題 |
No.2290 UnUnion Find
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-15 18:10:27 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,423 bytes |
| コンパイル時間 | 5,821 ms |
| コンパイル使用メモリ | 336,132 KB |
| 実行使用メモリ | 11,844 KB |
| 最終ジャッジ日時 | 2025-07-15 18:10:47 |
| 合計ジャッジ時間 | 19,230 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 39 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using int128 = __int128;
using State = string::const_iterator;
class ParseError {};
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define reps(i, l, r) for(ll i = (l); i < (r); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
// #define endl "\n";
const ll INF = LLONG_MAX / 4;
const ld inf = numeric_limits<long double>::max() / (ld)4;
const ll mod1 = 1000000007;
const ll mod2 = 998244353;
const ld pi = 3.1415926535897;
ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) { a = b; return true; }
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) { a = b; return true; }
return false;
}
const string TERM_RED = "\033[31m";
const string TERM_RESET = "\033[0m";
template <typename T>
void dump(const T &val) {
cerr << TERM_RED << "[[ DEBUG ]] " << val << TERM_RESET << std::endl;
}
using pii = pair<int, int>;
using vb = vector<bool>;
using vvb = vector<vb>;
template<typename T>
using vec = vector<T>;
int solve() {
int n, q;
cin >> n >> q;
dsu uf(n);
vec<int> queries;
vec<int> ans(q, 0);
vec<vec<int>> waiting(n);
rep(i, q) {
int t;
cin >> t;
if(t == 1) {
int u, v;
cin >> u >> v;
u--;
v--;
if(uf.same(u, v)) continue;
for(auto e : waiting[uf.leader(u)]) {
ans[e] = v+1;
}
waiting[uf.leader(u)].clear();
for(auto e : waiting[uf.leader(v)]) {
ans[e] = u+1;
}
waiting[uf.leader(v)].clear();
uf.merge(u, v);
} else {
int v;
cin >> v;
v--;
if(uf.size(v) == n) ans[i] = -1;
else waiting[uf.leader(v)].push_back(i);
}
}
rep(i, n) {
if(uf.same(0, i)) continue;
cout << i << endl;
for(auto e : waiting[0]) {
ans[e] = i+1;
}
waiting[0].clear();
for(auto e : waiting[i]) {
ans[e] = 1;
}
waiting[i].clear();
uf.merge(0, i);
}
rep(i, q) {
if(ans[i] != 0)
cout << ans[i] << endl;
}
return 0;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int t = 1;
while(t) {
// dump("case");
t = solve();
}
}