結果

問題 No.1843 Tree ANDistance
ユーザー 👑 tatyamtatyam
提出日時 2021-12-18 23:54:29
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 3,727 ms
コンパイル使用メモリ 253,376 KB
実行使用メモリ 4,680 KB
最終ジャッジ日時 2023-10-13 18:24:06
合計ジャッジ時間 9,711 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
4,596 KB
testcase_01 AC 73 ms
4,608 KB
testcase_02 AC 70 ms
4,592 KB
testcase_03 AC 71 ms
4,520 KB
testcase_04 AC 74 ms
4,624 KB
testcase_05 AC 65 ms
4,592 KB
testcase_06 AC 74 ms
4,620 KB
testcase_07 AC 71 ms
4,568 KB
testcase_08 AC 73 ms
4,572 KB
testcase_09 AC 67 ms
4,500 KB
testcase_10 AC 66 ms
4,680 KB
testcase_11 AC 74 ms
4,672 KB
testcase_12 AC 59 ms
4,476 KB
testcase_13 AC 70 ms
4,484 KB
testcase_14 AC 4 ms
4,352 KB
testcase_15 AC 5 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 4 ms
4,352 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 1 ms
4,356 KB
testcase_28 AC 25 ms
4,348 KB
testcase_29 AC 18 ms
4,352 KB
testcase_30 AC 17 ms
4,352 KB
testcase_31 AC 28 ms
4,380 KB
testcase_32 AC 26 ms
4,372 KB
testcase_33 AC 9 ms
4,352 KB
testcase_34 AC 21 ms
4,372 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/dsu>
using namespace std;
using Modint = atcoder::modint1000000007;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<array<int, 3>> edge(N - 1);
    for(auto& [A, B, C] : edge){
        cin >> A >> B >> C;
        A--; B--;
    }
    Modint ans = 0;
    for(int i = 30; i--; ){
        ans += ans;
        atcoder::dsu uf(N);
        for(auto [A, B, C] : edge) if(C >> i & 1){
            ans += uf.size(A) * uf.size(B);
            uf.merge(A, B);
        }
    }
    cout << ans.val() << endl;
}
0