結果

問題 No.2072 Anatomy
ユーザー suisui
提出日時 2022-09-16 22:33:00
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 4,011 ms
使用メモリ 8,752 KB
最終ジャッジ日時 2023-01-11 07:48:31
合計ジャッジ時間 8,020 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
4,904 KB
testcase_01 AC 2 ms
4,904 KB
testcase_02 AC 1 ms
6,952 KB
testcase_03 AC 1 ms
4,904 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 2 ms
4,904 KB
testcase_06 AC 1 ms
4,900 KB
testcase_07 AC 1 ms
4,904 KB
testcase_08 AC 104 ms
8,500 KB
testcase_09 AC 112 ms
8,108 KB
testcase_10 AC 108 ms
8,604 KB
testcase_11 AC 112 ms
8,176 KB
testcase_12 AC 88 ms
7,816 KB
testcase_13 AC 116 ms
8,440 KB
testcase_14 AC 73 ms
6,192 KB
testcase_15 AC 69 ms
6,452 KB
testcase_16 AC 115 ms
8,488 KB
testcase_17 AC 112 ms
8,532 KB
testcase_18 AC 58 ms
5,984 KB
testcase_19 AC 118 ms
8,584 KB
testcase_20 AC 119 ms
8,752 KB
testcase_21 AC 113 ms
8,552 KB
testcase_22 AC 118 ms
8,696 KB
testcase_23 AC 117 ms
8,520 KB
testcase_24 AC 114 ms
8,588 KB
testcase_25 AC 118 ms
8,652 KB
testcase_26 AC 1 ms
4,900 KB
testcase_27 AC 116 ms
8,684 KB
testcase_28 AC 117 ms
8,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n+1); i++)
#define repn(i,a,b) for (int i = (int)(a) ; i < (int)(b+1); i++)
#define repv(i, n) for (ll i = (ll)(n-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define cauto const auto&
#define bit(n) (1LL<<(n))
#define uni(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<int, P>;
using Graph = vector<vector<int>>;
using mint = modint998244353;
#ifdef LOCAL
    #include <debug.hpp>
    #define debug(...) debug::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
    #define debug(...) (static_cast<void>(0))
#endif

int main(){
    ll n,m;
    cin >> n >> m;
    vector<P> uv;
    rep(i,m){
        ll u,v;
        cin >> u >> v;
        u--; v--;
        uv.push_back({u,v});
    }
    dsu d(n);
    vector<ll> ans(n,0);
    repv(i,m){
        if(d.same(uv[i].first,uv[i].second)){
            ans[d.leader(uv[i].first)]++;
            continue;
        }
        ll tmp1 = d.leader(uv[i].first);
        ll tmp2 = d.leader(uv[i].second);
        d.merge(uv[i].first,uv[i].second);
        ans[d.leader(uv[i].first)] = max(ans[tmp1] ,ans[tmp2])+1;
    }
    cout << ans[d.leader(uv[0].first)] << endl;
    return 0;
}
0