結果

問題 No.2072 Anatomy
ユーザー ripityripity
提出日時 2022-10-30 13:05:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 4,526 ms
コンパイル使用メモリ 261,176 KB
実行使用メモリ 6,368 KB
最終ジャッジ日時 2023-09-21 11:25:56
合計ジャッジ時間 10,677 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 101 ms
5,832 KB
testcase_09 AC 107 ms
5,932 KB
testcase_10 AC 105 ms
5,404 KB
testcase_11 AC 108 ms
5,996 KB
testcase_12 AC 85 ms
5,476 KB
testcase_13 AC 112 ms
5,896 KB
testcase_14 AC 72 ms
4,980 KB
testcase_15 AC 67 ms
5,040 KB
testcase_16 AC 114 ms
6,276 KB
testcase_17 AC 111 ms
6,116 KB
testcase_18 AC 57 ms
4,800 KB
testcase_19 AC 117 ms
6,364 KB
testcase_20 AC 115 ms
6,204 KB
testcase_21 AC 112 ms
6,256 KB
testcase_22 AC 115 ms
6,156 KB
testcase_23 AC 114 ms
6,196 KB
testcase_24 AC 111 ms
6,364 KB
testcase_25 AC 115 ms
6,368 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 114 ms
6,200 KB
testcase_28 AC 113 ms
6,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  dsu uf(N);
  vector<int> u(M), v(M), dp(N);
  for( int i = 0; i < M; i++ ) {
    cin >> u[i] >> v[i];
    u[i]--; v[i]--;
  }
  reverse(u.begin(), u.end());
  reverse(v.begin(), v.end());
  for( int i = 0; i < M; i++ ) {
    int ul = uf.leader(u[i]), vl = uf.leader(v[i]), m = max(dp[ul], dp[vl]);
    dp[ul] = m+1;
    dp[vl] = m+1;
    uf.merge(u[i], v[i]);
  }
  for( int i = 0; i < N; i++ ) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
0