結果
問題 | No.2072 Anatomy |
ユーザー |
![]() |
提出日時 | 2022-10-20 10:44:58 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 1,953 bytes |
コンパイル時間 | 10,740 ms |
コンパイル使用メモリ | 285,300 KB |
最終ジャッジ日時 | 2025-02-08 08:36:25 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize(1) #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC target("popcnt") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef string str; typedef pair<ll,ll> pii; #define F first #define S second #define pb push_back #define pq priority_queue #define all(x) (x).begin(),(x).end() #define bug(x) cerr << (x) << '\n' #define yn(x) cout << (x==1?"Yes\n":"No\n") #define PI 3.14159265358979323 #define Ststone ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) const ll max_n=2e5+20,max_int=2147483647,mod1=1e9+7,mod2=998244353; const bool online = 0; ll dx[8] = {1,0,0,-1,1,1,-1,-1}; ll dy[8] = {0,1,-1,0,1,-1,1,-1}; ll t,n,q,m,a,b,c,d,e,dsu[max_n],dp[max_n]; vector<ll> v,v1,v2,v3,v4,vv; vector<pii> edge; char cc; str s; ll query(ll dot){ if(dsu[dot]==dot) return dot; else dsu[dot] = query(dsu[dot]); return dsu[dot]; } void merge(ll a,ll b){ if(a>b) swap(a,b); dsu[b] = a; } void solve(){ cin >> n >> m; for(ll i=0;i<max_n;i++) dsu[i] = i; for(ll i=0;i<m;i++){ cin >> a >> b; edge.pb({a,b}); } for(ll i=m-1;i>=0;i--){ ll x = edge[i].F,y = edge[i].S; //cerr << query(x) << ' ' << query(y) << '\n'; if(query(x)==query(y)){ dp[query(x)]++; } else{ ll sum = max(dp[query(x)],dp[query(y)])+1; merge(query(x),query(y)); dp[query(x)] = sum; } } ll cnt = 0; for(ll i=1;i<=n;i++){ cnt = max(dp[query(i)],cnt); dp[query(i)] = 0; } cout << cnt << '\n'; } int main(){ Ststone; if(online){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #else #endif } //cin >> t; t = 1; for(ll i=1;i<=t;i++){ //cout << "Case #"<<i<<": "; solve(); } } /* */