結果
問題 | No.2072 Anatomy |
ユーザー |
|
提出日時 | 2022-09-16 22:05:34 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 1,477 bytes |
コンパイル時間 | 2,161 ms |
使用メモリ | 6,952 KB |
最終ジャッジ日時 | 2023-01-11 07:06:54 |
合計ジャッジ時間 | 4,467 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,904 KB |
testcase_01 | AC | 1 ms
4,904 KB |
testcase_02 | AC | 1 ms
4,904 KB |
testcase_03 | AC | 2 ms
4,900 KB |
testcase_04 | AC | 1 ms
6,952 KB |
testcase_05 | AC | 1 ms
4,900 KB |
testcase_06 | AC | 2 ms
4,904 KB |
testcase_07 | AC | 2 ms
4,900 KB |
testcase_08 | AC | 37 ms
6,948 KB |
testcase_09 | AC | 37 ms
6,948 KB |
testcase_10 | AC | 38 ms
5,396 KB |
testcase_11 | AC | 39 ms
5,892 KB |
testcase_12 | AC | 31 ms
5,292 KB |
testcase_13 | AC | 41 ms
6,264 KB |
testcase_14 | AC | 26 ms
6,948 KB |
testcase_15 | AC | 23 ms
4,920 KB |
testcase_16 | AC | 42 ms
6,148 KB |
testcase_17 | AC | 39 ms
5,884 KB |
testcase_18 | AC | 21 ms
6,948 KB |
testcase_19 | AC | 41 ms
6,952 KB |
testcase_20 | AC | 42 ms
6,244 KB |
testcase_21 | AC | 40 ms
6,156 KB |
testcase_22 | AC | 43 ms
6,216 KB |
testcase_23 | AC | 40 ms
6,248 KB |
testcase_24 | AC | 38 ms
6,240 KB |
testcase_25 | AC | 42 ms
6,188 KB |
testcase_26 | AC | 2 ms
4,904 KB |
testcase_27 | AC | 40 ms
6,952 KB |
testcase_28 | AC | 38 ms
6,148 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef _RUTHEN #include <debug.hpp> #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template <class T> using V = vector<T>; struct unionfind { std::vector<int> parents; unionfind() {} unionfind(int n) : parents(n, -1) {} int leader(int x) { return parents[x] < 0 ? x : parents[x] = leader(parents[x]); } bool merge(int x, int y) { x = leader(x), y = leader(y); if (x == y) return false; if (parents[x] > parents[y]) std::swap(x, y); parents[x] += parents[y]; parents[y] = x; return true; } bool same(int x, int y) { return leader(x) == leader(y); } int size(int x) { return -parents[leader(x)]; } void init(int n) { parents.assign(n, -1); } // reset }; /** * @brief UnionFind * @docs docs/data_structure/unionfind.md */ int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; V<int> A(M), B(M); rep(i, M) { cin >> A[i] >> B[i]; A[i]--, B[i]--; } reverse(A.begin(), A.end()); reverse(B.begin(), B.end()); V<int> t(N); unionfind uf(N); rep(i, M) { int x = uf.leader(A[i]), y = uf.leader(B[i]); int r = max(t[x], t[y]); t[x] = t[y] = r + 1; uf.merge(A[i], B[i]); } int ans = *max_element(t.begin(), t.end()); cout << ans << '\n'; return 0; }