結果
問題 | No.2072 Anatomy |
ユーザー |
|
提出日時 | 2022-09-16 23:27:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 1,144 bytes |
コンパイル時間 | 2,216 ms |
コンパイル使用メモリ | 200,428 KB |
最終ジャッジ日時 | 2025-02-07 10:41:11 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;class dsu {vector<int> p;vector<int> sz;public:dsu(int n) : p(n), sz(n, 1) { iota(p.begin(), p.end(), 0); }inline int get(int x) {if (x == p[x]) {return x;}return p[x] = get(p[x]);}inline bool unite(int x, int y) {x = get(x);y = get(y);if (x != y) {if (sz[x] < sz[y]) {swap(x, y);}p[y] = x;sz[x] += sz[y];return true;}return false;}inline int size(int x) {x = get(x);return sz[x];}};int main() {iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0);int n, m;cin >> n >> m;vector<pair<int, int>> A(m);for (auto &p : A) {int x, y;cin >> x >> y;x--, y--;p = {x, y};}vector<int> cnt(n);reverse(A.begin(), A.end());dsu uf(n + 1);for (auto [x, y] : A) {int px = uf.get(x), py = uf.get(y);uf.unite(x, y);if (px == py) {cnt[uf.get(x)] = cnt[px] + 1;} else {cnt[uf.get(x)] = max(cnt[px], cnt[py]) + 1;}}cout << *max_element(cnt.begin(), cnt.end()) << '\n';return 0;}