結果
問題 | No.2072 Anatomy |
ユーザー | tktk_snsn |
提出日時 | 2022-09-17 09:07:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 2,191 bytes |
コンパイル時間 | 880 ms |
コンパイル使用メモリ | 97,512 KB |
実行使用メモリ | 6,416 KB |
最終ジャッジ日時 | 2023-08-23 17:30:04 |
合計ジャッジ時間 | 4,744 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 96 ms
5,740 KB |
testcase_09 | AC | 105 ms
6,000 KB |
testcase_10 | AC | 103 ms
5,488 KB |
testcase_11 | AC | 104 ms
5,980 KB |
testcase_12 | AC | 82 ms
5,272 KB |
testcase_13 | AC | 108 ms
6,416 KB |
testcase_14 | AC | 70 ms
4,948 KB |
testcase_15 | AC | 63 ms
4,884 KB |
testcase_16 | AC | 111 ms
5,876 KB |
testcase_17 | AC | 105 ms
5,944 KB |
testcase_18 | AC | 56 ms
4,572 KB |
testcase_19 | AC | 111 ms
6,268 KB |
testcase_20 | AC | 111 ms
6,276 KB |
testcase_21 | AC | 105 ms
6,244 KB |
testcase_22 | AC | 111 ms
6,248 KB |
testcase_23 | AC | 108 ms
6,288 KB |
testcase_24 | AC | 111 ms
6,160 KB |
testcase_25 | AC | 112 ms
6,156 KB |
testcase_26 | AC | 2 ms
4,384 KB |
testcase_27 | AC | 111 ms
6,208 KB |
testcase_28 | AC | 110 ms
6,136 KB |
ソースコード
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <set> #include <stack> #include <queue> #include <cmath> #include <iomanip> #include <numeric> #include <string> #include <bitset> #include <assert.h> // #define _GLIBCXX_DEBUG // #define _LIBCPP_DEBUG 0 #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define revrep(i, n) for(int i = (int)(n -1); i >= 0; --i) #define range(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define revrange(i, s, t) for(int i = (int)(t - 1); i >= (int)(s); --i) #define srange(i, s, t, step) for(int i = (int)(s); i < (int)(t); i+=int(step)) #define popcnt(x) __builtin_popcountll(x) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } inline bool inside(int x, int y, int h, int w) { return (x >= 0 && x < h && y >= 0 && y < w); } int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1, 0}; struct union_find{ public: union_find(int size): _n(size), root(size, -1) {} int find(int x){ if (root[x] < 0) return x; root[x] = find(root[x]); return root[x]; } bool same(int x, int y){ return find(x) == find(y); } bool merge(int x, int y){ x = find(x); y = find(y); if (x == y) return false; if (-root[x] < -root[y]) swap(x, y); root[x] += root[y]; root[y] = x; return true; } int size(int x){ return -root[x]; } private: int _n; vector<int> root; }; int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m); rep(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } union_find uf(n); vector<int> cnt(n, 0); revrep(i, m) { int p = uf.find(a[i]); int q = uf.find(b[i]); int x = max(cnt[p], cnt[q]); uf.merge(p, q); cnt[uf.find(p)] = x + 1; } int ans = 0; rep(i, n) chmax(ans, cnt[i]); cout << ans << endl; return 0; }