結果

問題 No.2072 Anatomy
ユーザー Nzt3Nzt3
提出日時 2022-09-16 23:00:41
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 205,800 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-12-21 22:28:42
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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