結果

問題 No.1843 Tree ANDistance
ユーザー HentciHentci
提出日時 2022-02-24 14:35:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 346 ms / 2,000 ms
コード長 1,076 bytes
コンパイル時間 3,790 ms
コンパイル使用メモリ 209,420 KB
実行使用メモリ 12,268 KB
最終ジャッジ日時 2023-09-15 08:20:38
合計ジャッジ時間 10,671 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 322 ms
12,144 KB
testcase_01 AC 323 ms
12,268 KB
testcase_02 AC 314 ms
12,180 KB
testcase_03 AC 312 ms
12,056 KB
testcase_04 AC 319 ms
12,084 KB
testcase_05 AC 290 ms
12,084 KB
testcase_06 AC 301 ms
12,164 KB
testcase_07 AC 306 ms
11,640 KB
testcase_08 AC 312 ms
11,932 KB
testcase_09 AC 302 ms
11,596 KB
testcase_10 AC 294 ms
11,240 KB
testcase_11 AC 321 ms
11,784 KB
testcase_12 AC 261 ms
11,404 KB
testcase_13 AC 346 ms
11,424 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 297 ms
10,144 KB
testcase_29 AC 198 ms
7,828 KB
testcase_30 AC 169 ms
7,868 KB
testcase_31 AC 336 ms
10,752 KB
testcase_32 AC 313 ms
10,228 KB
testcase_33 AC 85 ms
5,428 KB
testcase_34 AC 241 ms
8,532 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/dsu.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define ll long long
#define all(x) x.begin(),x.end()
#define ar array
#define sz(x) ((int)x.size())
#define lazycalc S, op, e, F, mapping, composition, id
#define segcalc S, op, e
template <class T,class S> inline bool chmin(T &a,const S &b) {return (a> b? a= b, 1: 0);}
template <class T,class S> inline bool chmax(T &a,const S &b) {return (a< b? a= b, 1: 0);}
const int mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0);
    int n;
    cin >> n;
    vector <ar<ll, 3>> G(n - 1);
    for(auto &[a, b, c]: G){
        cin >> a >> b >> c;
        --a, --b;
    }
    
    ll ans = 0;
    for(int i = 0;i < 32;i++){
        dsu d(n);
        for(auto [a, b, c]: G){
            if(c >> i & 1)
                d.merge(a, b);
        }
        for(auto ele: d.groups()){
            ll SZ = ele.size() % mod;
            SZ = SZ * (SZ - 1) / 2 % mod;
            ans = (ans + SZ * (1 << i)) % mod;
        }
    }

    cout << ans << "\n";

    return 0;
}
0