結果

問題 No.1843 Tree ANDistance
ユーザー nononnonon
提出日時 2024-01-11 11:39:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 640 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 2,578 ms
コンパイル使用メモリ 213,860 KB
実行使用メモリ 10,064 KB
最終ジャッジ日時 2024-01-11 11:39:51
合計ジャッジ時間 16,729 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 521 ms
9,920 KB
testcase_01 AC 545 ms
9,936 KB
testcase_02 AC 511 ms
9,888 KB
testcase_03 AC 528 ms
9,884 KB
testcase_04 AC 517 ms
9,916 KB
testcase_05 AC 478 ms
10,064 KB
testcase_06 AC 510 ms
10,016 KB
testcase_07 AC 491 ms
9,536 KB
testcase_08 AC 533 ms
9,728 KB
testcase_09 AC 482 ms
9,492 KB
testcase_10 AC 474 ms
9,428 KB
testcase_11 AC 540 ms
9,896 KB
testcase_12 AC 433 ms
9,428 KB
testcase_13 AC 547 ms
9,216 KB
testcase_14 AC 18 ms
6,676 KB
testcase_15 AC 20 ms
6,676 KB
testcase_16 AC 9 ms
6,676 KB
testcase_17 AC 9 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 21 ms
6,676 KB
testcase_20 AC 11 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 584 ms
9,300 KB
testcase_29 AC 417 ms
7,372 KB
testcase_30 AC 369 ms
7,724 KB
testcase_31 AC 640 ms
9,832 KB
testcase_32 AC 621 ms
9,492 KB
testcase_33 AC 182 ms
6,676 KB
testcase_34 AC 471 ms
8,116 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/dsu>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint1000000007;
int N;
int u[1<<17],v[1<<17],w[1<<17];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N;
    for(int i=1;i<N;i++)
    {
        cin>>u[i]>>v[i]>>w[i];
        u[i]--,v[i]--;
    }
    mint ans=0;
    for(int i=0;i<30;i++)
    {
        atcoder::dsu uf(N);
        for(int j=1;j<N;j++)
        {
            if(w[j]&(1<<i))uf.merge(u[j],v[j]);
        }
        for(vector<int>v:uf.groups())
        {
            int n=v.size();
            ans+=mint(n)*(n-1)/2*(1<<i);
        }
    }
    cout << ans.val() << endl;
}
0