結果

問題 No.2072 Anatomy
ユーザー otoshigootoshigo
提出日時 2022-09-16 21:44:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,717 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 206,884 KB
実行使用メモリ 11,756 KB
最終ジャッジ日時 2023-08-23 14:45:09
合計ジャッジ時間 4,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,092 KB
testcase_01 AC 4 ms
8,180 KB
testcase_02 AC 4 ms
8,040 KB
testcase_03 AC 5 ms
8,228 KB
testcase_04 AC 5 ms
8,128 KB
testcase_05 AC 5 ms
8,184 KB
testcase_06 AC 4 ms
8,112 KB
testcase_07 AC 5 ms
8,108 KB
testcase_08 AC 46 ms
11,056 KB
testcase_09 AC 45 ms
11,296 KB
testcase_10 AC 46 ms
10,600 KB
testcase_11 AC 48 ms
11,060 KB
testcase_12 AC 38 ms
10,240 KB
testcase_13 AC 50 ms
11,668 KB
testcase_14 AC 33 ms
9,944 KB
testcase_15 AC 30 ms
10,016 KB
testcase_16 AC 52 ms
11,664 KB
testcase_17 AC 48 ms
11,444 KB
testcase_18 AC 27 ms
9,876 KB
testcase_19 AC 51 ms
11,588 KB
testcase_20 AC 52 ms
11,744 KB
testcase_21 AC 48 ms
11,680 KB
testcase_22 AC 52 ms
11,688 KB
testcase_23 AC 49 ms
11,620 KB
testcase_24 AC 47 ms
11,640 KB
testcase_25 AC 50 ms
11,620 KB
testcase_26 AC 4 ms
8,100 KB
testcase_27 AC 50 ms
11,688 KB
testcase_28 AC 48 ms
11,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = (n) - 1; i >= 0; i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

struct UnionFind {
    vector<int> par, siz;
    UnionFind(int n) : par(n,-1), siz(n,1) {}
    int find(int x){
        if (par[x] == -1) return x;
        else{
            par[x] = find(par[x]);
            return par[x];
        }
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (siz[x] < siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y] = x;
    }
};

int n, m;
vector<int> g[200010];

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> n >> m;
    vector<pair<int, int>> vp;
    rep(i, m){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        vp.push_back(make_pair(u, v));
    }
    reverse(all(vp));
    UnionFind uf(n);
    vector<int> d(n);
    for (auto [u, v] : vp){
        int eu = uf.find(u), ev = uf.find(v);
        if (uf.same(u, v)){
            d[eu]++;
        } else{
            int pu = d[eu], pv = d[ev];
            d[eu] = d[ev] = 0;
            uf.unite(u, v);
            d[uf.find(u)] = max(pu, pv) + 1;
        }
    }
    int ans = 0;
    rep(i, n){
        chmax(ans, d[i]);
    }
    cout << ans << "\n";
}
0