結果

問題 No.2290 UnUnion Find
ユーザー Ricky_pon
提出日時 2023-05-05 21:27:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 2,629 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 140,148 KB
最終ジャッジ日時 2025-02-12 17:31:56
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:99:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   99 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:105:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  105 |         scanf("%d", &type);
      |         ~~~~~^~~~~~~~~~~~~
main.cpp:108:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  108 |             scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
main.cpp:116:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  116 |             scanf("%d", &v);
      |             ~~~~~^~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

// #include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, l, r) for (int i = int(l), rr = int(r); i < rr; ++i)
#define repin(i, l, r) for (int i = int(l), rr = int(r); i <= rr; ++i)
#define rep0(i, n) rep(i, 0, n)
#define rrep(i, l, r) for (int i = int(r) - 1, ll = int(l); i >= ll; --i)
#define rrepin(i, l, r) for (int i = int(r), ll = int(l); i >= ll; --i)
#define rrep0(i, n) rrep(i, 0, n)
#define fi first
#define se second
#include <atcoder/dsu>
#include <algorithm>
#include <cassert>
#include <vector>
namespace rklib {
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin_non_negative(T &a, const T &b) {
if (a < 0 || a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
} // namespace rklib
using namespace std;
using namespace rklib;
using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
int main() {
int n, q;
scanf("%d%d", &n, &q);
atcoder::dsu uf(n);
set<int> roots;
rep0(i, n) roots.insert(i);
rep0(qq, q) {
int type;
scanf("%d", &type);
if (type == 1) {
int a, b;
scanf("%d%d", &a, &b);
--a;
--b;
roots.erase(uf.leader(a));
roots.erase(uf.leader(b));
roots.insert(uf.merge(a, b));
} else {
int v;
scanf("%d", &v);
--v;
v = uf.leader(v);
if (roots.size() == 1) {
puts("-1");
} else {
printf("%d\n", *roots.begin() == v ? *roots.rbegin() + 1
: *roots.begin() + 1);
}
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0