結果

問題 No.2072 Anatomy
ユーザー Nzt3Nzt3
提出日時 2022-09-16 23:00:41
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 2,125 ms
使用メモリ 6,976 KB
最終ジャッジ日時 2023-01-11 08:18:55
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
5,104 KB
testcase_01 AC 3 ms
5,004 KB
testcase_02 AC 2 ms
6,952 KB
testcase_03 AC 3 ms
4,964 KB
testcase_04 AC 3 ms
5,104 KB
testcase_05 AC 3 ms
6,948 KB
testcase_06 AC 3 ms
5,092 KB
testcase_07 AC 3 ms
4,964 KB
testcase_08 AC 37 ms
6,948 KB
testcase_09 AC 36 ms
6,948 KB
testcase_10 AC 42 ms
5,888 KB
testcase_11 AC 40 ms
6,952 KB
testcase_12 AC 34 ms
5,628 KB
testcase_13 AC 39 ms
6,340 KB
testcase_14 AC 29 ms
5,716 KB
testcase_15 AC 25 ms
5,724 KB
testcase_16 AC 43 ms
6,252 KB
testcase_17 AC 39 ms
6,148 KB
testcase_18 AC 21 ms
5,456 KB
testcase_19 AC 40 ms
6,948 KB
testcase_20 AC 41 ms
6,156 KB
testcase_21 AC 39 ms
6,256 KB
testcase_22 AC 44 ms
6,952 KB
testcase_23 AC 39 ms
6,148 KB
testcase_24 AC 39 ms
6,976 KB
testcase_25 AC 40 ms
6,952 KB
testcase_26 AC 3 ms
5,112 KB
testcase_27 AC 40 ms
6,500 KB
testcase_28 AC 38 ms
6,952 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