結果

問題 No.1843 Tree ANDistance
ユーザー ShirotsumeShirotsume
提出日時 2022-02-18 22:06:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,252 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 4,303 ms
コンパイル使用メモリ 267,824 KB
実行使用メモリ 13,712 KB
最終ジャッジ日時 2023-09-11 19:14:28
合計ジャッジ時間 28,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,159 ms
13,684 KB
testcase_01 AC 1,137 ms
13,684 KB
testcase_02 AC 1,161 ms
13,680 KB
testcase_03 AC 1,156 ms
13,548 KB
testcase_04 AC 1,152 ms
13,676 KB
testcase_05 AC 935 ms
13,684 KB
testcase_06 AC 948 ms
13,712 KB
testcase_07 AC 1,094 ms
13,036 KB
testcase_08 AC 1,097 ms
13,576 KB
testcase_09 AC 1,085 ms
13,116 KB
testcase_10 AC 1,063 ms
12,888 KB
testcase_11 AC 1,131 ms
13,636 KB
testcase_12 AC 801 ms
12,612 KB
testcase_13 AC 856 ms
12,876 KB
testcase_14 AC 29 ms
4,376 KB
testcase_15 AC 31 ms
4,376 KB
testcase_16 AC 13 ms
4,380 KB
testcase_17 AC 12 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 27 ms
4,376 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1,068 ms
11,236 KB
testcase_29 AC 673 ms
8,576 KB
testcase_30 AC 736 ms
8,720 KB
testcase_31 AC 1,252 ms
11,936 KB
testcase_32 AC 1,100 ms
11,292 KB
testcase_33 AC 324 ms
5,896 KB
testcase_34 AC 866 ms
9,688 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define mint modint1000000007
int main(void)
{
    int n;
    cin >> n;
    mint ans, bi2;
    bi2 = 1;
    vector<vector<int>> abc(n, vector<int>(3));
    rep(i, n - 1)rep(j, 3){
        cin >> abc[i][j];
    }
    rep(bit, 32){
        dsu U(n + 1);
        rep(i, n - 1){
            int a = abc[i][0];
            int b = abc[i][1]; 
            int c = abc[i][2];
            if(1 & (c >> bit)) U.merge(a - 1, b - 1);
        }
        map<int, int> s;
        rep(i, n){
            int x = U.leader(i);
            if (s.find(x) != s.end()) continue;
            else{
                s[x] = 1;
                mint c = U.size(i);
                ans += bi2 * c * (c - 1) / 2;
            }
        }
        bi2 *= 2;

    }
    cout << ans.val() << endl;
    return 0;
}
0