結果

問題 No.2072 Anatomy
ユーザー Nzt3Nzt3
提出日時 2022-09-16 23:00:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 201,532 KB
実行使用メモリ 6,964 KB
最終ジャッジ日時 2023-08-23 16:29:07
合計ジャッジ時間 4,461 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,980 KB
testcase_01 AC 3 ms
4,964 KB
testcase_02 AC 3 ms
4,924 KB
testcase_03 AC 3 ms
4,884 KB
testcase_04 AC 3 ms
4,912 KB
testcase_05 AC 3 ms
4,932 KB
testcase_06 AC 3 ms
4,932 KB
testcase_07 AC 3 ms
5,148 KB
testcase_08 AC 39 ms
5,984 KB
testcase_09 AC 39 ms
5,876 KB
testcase_10 AC 44 ms
6,248 KB
testcase_11 AC 43 ms
6,248 KB
testcase_12 AC 35 ms
5,928 KB
testcase_13 AC 41 ms
6,248 KB
testcase_14 AC 30 ms
5,588 KB
testcase_15 AC 26 ms
5,788 KB
testcase_16 AC 46 ms
6,168 KB
testcase_17 AC 41 ms
6,252 KB
testcase_18 AC 22 ms
5,452 KB
testcase_19 AC 43 ms
6,284 KB
testcase_20 AC 44 ms
6,112 KB
testcase_21 AC 42 ms
6,132 KB
testcase_22 AC 47 ms
6,248 KB
testcase_23 AC 42 ms
6,152 KB
testcase_24 AC 42 ms
6,964 KB
testcase_25 AC 42 ms
6,244 KB
testcase_26 AC 3 ms
5,092 KB
testcase_27 AC 43 ms
6,584 KB
testcase_28 AC 40 ms
6,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int rt[200000];
int ans[200000];
int getroot(int n){
  if(rt[n]==-1)return n;
  return rt[n]=getroot(rt[n]);
}

void unite(int a,int b){
  a=getroot(a),b=getroot(b);
  if(a!=b){
    rt[a]=b;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  fill(rt,rt+200000,-1);
  fill(ans,ans+200000,0);
  int N,M;
  cin>>N>>M;
  vector<array<int,2>>E(M);
  for(auto &i:E)cin>>i[0]>>i[1],--i[0],--i[1];
  int ret=0;
  for(int i=M-1;i>=0;i--){
    int p=max(ans[getroot(E[i][0])],ans[getroot(E[i][1])]);
    unite(E[i][0],E[i][1]);
    ans[getroot(E[i][0])]=p+1;
    ret=max(ret,ans[getroot(E[i][0])]);
  }
  cout<<ret<<'\n';
}
0