結果

問題 No.2072 Anatomy
ユーザー やうやう
提出日時 2022-09-16 22:13:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 169,388 KB
実行使用メモリ 9,784 KB
最終ジャッジ日時 2023-08-23 15:50:15
合計ジャッジ時間 5,389 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,456 KB
testcase_01 AC 2 ms
4,644 KB
testcase_02 AC 3 ms
4,416 KB
testcase_03 AC 3 ms
4,608 KB
testcase_04 AC 2 ms
4,592 KB
testcase_05 AC 3 ms
4,700 KB
testcase_06 AC 3 ms
4,460 KB
testcase_07 AC 3 ms
4,524 KB
testcase_08 AC 106 ms
8,536 KB
testcase_09 AC 115 ms
9,248 KB
testcase_10 AC 115 ms
8,592 KB
testcase_11 AC 115 ms
8,992 KB
testcase_12 AC 94 ms
7,864 KB
testcase_13 AC 117 ms
9,204 KB
testcase_14 AC 85 ms
7,536 KB
testcase_15 AC 70 ms
7,536 KB
testcase_16 AC 123 ms
9,072 KB
testcase_17 AC 116 ms
9,404 KB
testcase_18 AC 61 ms
7,008 KB
testcase_19 AC 120 ms
9,556 KB
testcase_20 AC 121 ms
9,508 KB
testcase_21 AC 115 ms
9,384 KB
testcase_22 AC 125 ms
9,392 KB
testcase_23 AC 120 ms
9,380 KB
testcase_24 AC 115 ms
9,520 KB
testcase_25 AC 119 ms
9,388 KB
testcase_26 AC 3 ms
4,412 KB
testcase_27 AC 118 ms
9,784 KB
testcase_28 AC 118 ms
9,332 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