結果

問題 No.1843 Tree ANDistance
ユーザー ruthenruthen
提出日時 2022-02-18 22:22:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 1,652 ms
コンパイル使用メモリ 173,160 KB
実行使用メモリ 4,780 KB
最終ジャッジ日時 2023-09-11 19:28:40
合計ジャッジ時間 10,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 327 ms
4,564 KB
testcase_01 AC 327 ms
4,540 KB
testcase_02 AC 322 ms
4,536 KB
testcase_03 AC 321 ms
4,556 KB
testcase_04 AC 326 ms
4,780 KB
testcase_05 AC 315 ms
4,652 KB
testcase_06 AC 326 ms
4,616 KB
testcase_07 AC 310 ms
4,568 KB
testcase_08 AC 317 ms
4,536 KB
testcase_09 AC 304 ms
4,636 KB
testcase_10 AC 298 ms
4,544 KB
testcase_11 AC 323 ms
4,536 KB
testcase_12 AC 287 ms
4,400 KB
testcase_13 AC 304 ms
4,640 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 15 ms
4,380 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 360 ms
4,376 KB
testcase_29 AC 243 ms
4,380 KB
testcase_30 AC 252 ms
4,376 KB
testcase_31 AC 393 ms
4,660 KB
testcase_32 AC 368 ms
4,376 KB
testcase_33 AC 128 ms
4,380 KB
testcase_34 AC 292 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) begin(x), end(x)
template <class T> using V = vector<T>;

#include <atcoder/dsu>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<int> u(N - 1), v(N - 1), c(N - 1);
    rep(i, N - 1) {
        cin >> u[i] >> v[i] >> c[i];
        u[i]--, v[i]--;
    }
    mint p2 = 1, ans = 0;
    rep(i, 32) {
        dsu uf(N);
        rep(j, N - 1) {
            if (c[j] >> i & 1) {
                uf.merge(u[j], v[j]);
            }
        }
        rep(j, N) {
            if (uf.leader(j) == j) {
                ans += p2 * uf.size(j) * (uf.size(j) - 1) / 2;
            }
        }
        p2 *= 2;
    }
    cout << ans.val() << '\n';
    return 0;
}
0