結果

問題 No.2072 Anatomy
ユーザー tokumini_sstokumini_ss
提出日時 2022-09-16 22:09:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 208,484 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2023-08-23 15:43:17
合計ジャッジ時間 5,893 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 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 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 99 ms
7,724 KB
testcase_09 AC 109 ms
8,116 KB
testcase_10 AC 104 ms
7,368 KB
testcase_11 AC 108 ms
8,040 KB
testcase_12 AC 84 ms
6,792 KB
testcase_13 AC 110 ms
8,380 KB
testcase_14 AC 71 ms
6,324 KB
testcase_15 AC 65 ms
6,588 KB
testcase_16 AC 112 ms
8,380 KB
testcase_17 AC 109 ms
8,304 KB
testcase_18 AC 57 ms
5,884 KB
testcase_19 AC 114 ms
8,584 KB
testcase_20 AC 114 ms
8,572 KB
testcase_21 AC 110 ms
8,588 KB
testcase_22 AC 118 ms
8,640 KB
testcase_23 AC 114 ms
8,528 KB
testcase_24 AC 109 ms
8,568 KB
testcase_25 AC 112 ms
8,700 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 112 ms
8,648 KB
testcase_28 AC 111 ms
8,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/dsu>

int main() {
    int64_t N, M;
    cin >> N >> M;

    vector<int64_t> u(M), v(M);
    for (int64_t i = 0; i < M; i++) {
        cin >> u[i] >> v[i];
        u[i]--, v[i]--;
    }

    atcoder::dsu dsu(N);
    vector<int64_t> op_num(N, 0);
    for (int64_t i = M - 1; i >= 0; i--) {
        const int64_t lu = dsu.leader(u[i]);
        const int64_t lv = dsu.leader(v[i]);
        if (dsu.same(u[i], v[i])) {
            op_num[lu]++;
            continue;
        }
        const int64_t su = op_num[lu];
        const int64_t sv = op_num[lv];
        const int64_t l = dsu.merge(u[i], v[i]);
        op_num[l] = max(su, sv) + 1;
    }
    cout << *max_element(op_num.begin(), op_num.end()) << endl;
}
0