結果

問題 No.2072 Anatomy
ユーザー umezoumezo
提出日時 2022-09-17 07:00:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,481 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 210,252 KB
実行使用メモリ 21,520 KB
最終ジャッジ日時 2023-08-23 17:27:10
合計ジャッジ時間 5,615 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,068 KB
testcase_01 AC 4 ms
8,076 KB
testcase_02 AC 4 ms
8,092 KB
testcase_03 AC 5 ms
8,100 KB
testcase_04 AC 5 ms
8,068 KB
testcase_05 AC 5 ms
8,164 KB
testcase_06 AC 5 ms
8,132 KB
testcase_07 AC 4 ms
8,152 KB
testcase_08 AC 103 ms
19,036 KB
testcase_09 AC 68 ms
20,096 KB
testcase_10 AC 90 ms
18,532 KB
testcase_11 AC 83 ms
19,096 KB
testcase_12 AC 63 ms
16,932 KB
testcase_13 AC 115 ms
21,056 KB
testcase_14 AC 62 ms
15,596 KB
testcase_15 AC 45 ms
15,884 KB
testcase_16 AC 114 ms
20,880 KB
testcase_17 AC 84 ms
19,820 KB
testcase_18 AC 39 ms
14,468 KB
testcase_19 AC 124 ms
21,520 KB
testcase_20 AC 130 ms
20,920 KB
testcase_21 AC 84 ms
21,076 KB
testcase_22 AC 121 ms
21,144 KB
testcase_23 AC 86 ms
20,092 KB
testcase_24 AC 76 ms
21,196 KB
testcase_25 AC 125 ms
21,464 KB
testcase_26 AC 4 ms
8,064 KB
testcase_27 AC 90 ms
20,084 KB
testcase_28 AC 68 ms
20,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

class Dis{
  public:
  vector<ll> rank,p,siz;
  
  Dis(int s){
    rank.resize(s,0);
    p.resize(s,0);
    siz.resize(s,1);
    rep(i,s) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
  
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      siz[x]+=siz[y];
    }
    else{
      p[x]=y;
      siz[y]+=siz[x];
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int findSet(int x){
    if(x != p[x]) p[x]=findSet(p[x]);
    return p[x];
  }
  
  int size(int x){
    return siz[findSet(x)];
  }
};

vector<int> G[200200];
int A[200200];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n,m;
  cin>>n>>m;
  vector<int> U(m),V(m);
  rep(i,m){
    cin>>U[i]>>V[i];
    U[i]--,V[i]--;
  }
  
  Dis ds=Dis(m);
  
  int ma=0;
  for(int i=m-1;i>=0;i--){
    int t=0;
    if(G[U[i]].size()) t=max(t,A[ds.findSet(G[U[i]][0])]);
    if(G[V[i]].size()) t=max(t,A[ds.findSet(G[V[i]][0])]);
    if(G[U[i]].size()) ds.unite(i,G[U[i]][0]);
    if(G[V[i]].size()) ds.unite(i,G[V[i]][0]);
    ma=max(ma,t+1);
    A[ds.findSet(i)]=t+1;
    G[U[i]].push_back(i),G[V[i]].push_back(i);
  }
  cout<<ma<<endl;

  return 0;
}
0