結果

問題 No.2072 Anatomy
ユーザー やうやう
提出日時 2022-09-16 22:13:30
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 1,384 ms
使用メモリ 9,776 KB
最終ジャッジ日時 2023-01-11 07:22:06
合計ジャッジ時間 5,328 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
4,904 KB
testcase_01 AC 3 ms
4,900 KB
testcase_02 AC 2 ms
4,904 KB
testcase_03 AC 2 ms
6,952 KB
testcase_04 AC 2 ms
4,904 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 3 ms
6,952 KB
testcase_07 AC 2 ms
4,900 KB
testcase_08 AC 103 ms
8,588 KB
testcase_09 AC 113 ms
9,168 KB
testcase_10 AC 113 ms
8,680 KB
testcase_11 AC 112 ms
8,984 KB
testcase_12 AC 91 ms
7,804 KB
testcase_13 AC 113 ms
9,116 KB
testcase_14 AC 76 ms
7,612 KB
testcase_15 AC 69 ms
7,528 KB
testcase_16 AC 119 ms
9,108 KB
testcase_17 AC 111 ms
9,188 KB
testcase_18 AC 58 ms
7,028 KB
testcase_19 AC 117 ms
9,404 KB
testcase_20 AC 117 ms
9,372 KB
testcase_21 AC 113 ms
9,368 KB
testcase_22 AC 121 ms
9,488 KB
testcase_23 AC 114 ms
9,368 KB
testcase_24 AC 113 ms
9,364 KB
testcase_25 AC 116 ms
9,384 KB
testcase_26 AC 3 ms
4,900 KB
testcase_27 AC 116 ms
9,776 KB
testcase_28 AC 115 ms
9,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
using V=vector<ll>;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)

V k(202020,-1);

int root(int x){
    if(k[x]<0) return x;
    return k[x]=root(k[x]);
}

void unite(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return;
    k[y]=x;
}

int main(){
    int n,m;
    cin >> n >> m;
    V u(m),v(m);
    rep(i,m){
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }
    reverse(u.begin(),u.end());
    reverse(v.begin(),v.end());
    
    V a(n); ll ans=0;
    rep(i,m){
        a[root(u[i])]=a[root(v[i])]=max(a[root(u[i])],a[root(v[i])])+1;
        unite(u[i],v[i]);
    }
    rep(i,n) ans=max(ans,a[i]);
    cout << ans << endl;
}
0