結果

問題 No.2072 Anatomy
ユーザー SSRSSSRS
提出日時 2022-09-16 21:29:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 167,028 KB
実行使用メモリ 6,544 KB
最終ジャッジ日時 2023-08-23 14:27:21
合計ジャッジ時間 5,085 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 98 ms
5,596 KB
testcase_09 AC 105 ms
6,020 KB
testcase_10 AC 107 ms
5,340 KB
testcase_11 AC 105 ms
5,864 KB
testcase_12 AC 89 ms
5,048 KB
testcase_13 AC 106 ms
5,864 KB
testcase_14 AC 74 ms
4,964 KB
testcase_15 AC 64 ms
4,916 KB
testcase_16 AC 111 ms
6,268 KB
testcase_17 AC 105 ms
5,944 KB
testcase_18 AC 56 ms
4,644 KB
testcase_19 AC 109 ms
6,180 KB
testcase_20 AC 111 ms
6,268 KB
testcase_21 AC 108 ms
6,392 KB
testcase_22 AC 116 ms
6,272 KB
testcase_23 AC 111 ms
6,156 KB
testcase_24 AC 108 ms
6,544 KB
testcase_25 AC 113 ms
6,244 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 112 ms
6,520 KB
testcase_28 AC 113 ms
6,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct unionfind{
  vector<int> a;
  vector<int> p;
  unionfind(int N): a(N, 0), p(N, -1){
  }
  int root(int x){
    if (p[x] == -1){
      return x;
    } else {
      p[x] = root(p[x]);
      return p[x];
    }
  }
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if (x != y){
      p[y] = x;
      a[x] = max(a[x], a[y]);
    }
    a[x]++;
  }
};
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> u(M), v(M);
  for (int i = 0; i < M; i++){
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
  }
  unionfind UF(N);
  for (int i = M - 1; i >= 0; i--){
    UF.unite(u[i], v[i]);
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    ans = max(ans, UF.a[i]);
  }
  cout << ans << endl;
}
0