結果
| 問題 | No.2072 Anatomy | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-09-16 23:00:41 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 53 ms / 2,000 ms | 
| コード長 | 680 bytes | 
| コンパイル時間 | 2,047 ms | 
| コンパイル使用メモリ | 197,196 KB | 
| 最終ジャッジ日時 | 2025-02-07 10:30:57 | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 27 | 
ソースコード
#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';
}
            
            
            
        