結果
問題 | No.2072 Anatomy |
ユーザー |
![]() |
提出日時 | 2022-09-16 22:13:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 1,925 ms |
コンパイル使用メモリ | 171,232 KB |
実行使用メモリ | 9,856 KB |
最終ジャッジ日時 | 2024-12-21 21:14:50 |
合計ジャッジ時間 | 5,271 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#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; }