結果

問題 No.1843 Tree ANDistance
ユーザー 👑 colognecologne
提出日時 2022-03-14 20:14:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 710 bytes
コンパイル時間 4,897 ms
コンパイル使用メモリ 257,616 KB
実行使用メモリ 4,932 KB
最終ジャッジ日時 2023-10-21 07:13:15
合計ジャッジ時間 15,227 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 365 ms
4,932 KB
testcase_01 AC 368 ms
4,932 KB
testcase_02 AC 359 ms
4,932 KB
testcase_03 AC 358 ms
4,932 KB
testcase_04 AC 365 ms
4,932 KB
testcase_05 AC 352 ms
4,932 KB
testcase_06 AC 362 ms
4,932 KB
testcase_07 AC 346 ms
4,932 KB
testcase_08 AC 353 ms
4,932 KB
testcase_09 AC 340 ms
4,932 KB
testcase_10 AC 335 ms
4,932 KB
testcase_11 AC 367 ms
4,932 KB
testcase_12 AC 323 ms
4,812 KB
testcase_13 AC 337 ms
4,824 KB
testcase_14 AC 14 ms
4,348 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 17 ms
4,348 KB
testcase_20 AC 8 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 373 ms
4,668 KB
testcase_29 AC 252 ms
4,348 KB
testcase_30 AC 260 ms
4,348 KB
testcase_31 AC 408 ms
4,740 KB
testcase_32 AC 382 ms
4,676 KB
testcase_33 AC 132 ms
4,348 KB
testcase_34 AC 303 ms
4,404 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
#include <atcoder/modint>
using namespace std;
using Mint = atcoder::modint1000000007;
int main()
{
    int N;
    cin >> N;
    vector<tuple<int, int, int>> V(N - 1);

    for (auto &[a, b, c] : V)
        cin >> a >> b >> c;

    Mint ret = 0;

    for (int i = 0; i < 30; i++)
    {
        atcoder::dsu DSU(N);
        for (auto [a, b, c] : V)
            if (c & (1 << i))
                DSU.merge(a - 1, b - 1);
        Mint ans = 0;
        for (int i = 0; i < N; i++)
            if (i == DSU.leader(i))
                ans += Mint(DSU.size(i)) * Mint(DSU.size(i) - 1) / Mint(2);
        ret += ans * Mint(1 << i);
    }
    cout << ret.val() << endl;
}
0