問題一覧 > 通常問題

No.1843 Tree ANDistance

レベル : / AI推定難易度 : 1400 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 147
作問者 : 👑 potato167 / テスター : tatyam nok0
お気に入りにしたユーザー ProblemId : 7453 / 自分の提出
問題文最終更新日: 2022-01-15 01:00:26
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 332 (順位表) の他の問題:

Problem Statement

You are given a tree with $N$ vertices. The vertices of the tree are numbered from $1$ to $N$. The $i$-th edge of this tree connects vertices $A_i$ and $B_i$, and a positive integer $C_i$ is placed on the edge.

$\sum_{u=1}^{N-1}{ \sum_{v=u+1}^{N} \text{andist}(u,v)}$

Find the value of the above expression. Here, $\text{andist}(u,v)$ is the $\text{AND}$ of the numbers placed on the edges of the shortest path from vertex $u$ to vertex $v$. Since the answer can be very large, output it modulo $(10^9+7)$.

▼What is $\text{AND}$? Given numbers $x_1,x_2,...,x_n$, let $A$ be their $\text{AND}$. Then $A$ is defined as follows.
  • In the binary representation of $A$, the $2^k\,(0\leq k)$ place is $1$ if the $2^k$ place of every one of $x_1,x_2,\dots,x_n$ is $1$, and $0$ otherwise.
  • For example, given $3$ and $6$, their $\text{AND}$ is $2$.

    Constraints

    • $2\leq N \leq 10^5$
    • $1\leq A_{i} < B_{i}\leq N$
    • $1\leq C_i \leq 10^9$
    • The given graph is a tree.
    • All inputs are integers.

    Input

    $N$
    $ A_1 \; B_1 \; C_1$
    $ A_2 \; B_2 \; C_2$
    $ \vdots $
    $ A_{N-1} \; B_{N-1} \; C_{N-1}$
    

    Output

    Output the answer modulo $(10^{9}+7)$. Print a newline at the end.

    Sample

    Sample 1
    Input
    3
    1 2 5
    2 3 4
    
    Output
    13
    

    Since $\text{andist}(1,2)=5,\ \text{andist}(2,3)=4,\ \text{andist}(1,3)=4,\ 5+4+4=13$, output $13$.

    Sample 2
    Input
    2
    1 2 11111
    
    Output
    11111
    
    Sample 3
    Input
    10
    4 10 720486811
    3 6 815722764
    3 4 983953993
    8 10 211236348
    3 5 349109700
    5 9 338069808
    6 7 510511646
    1 5 367286770
    2 6 831398479
    
    Output
    819732336
    

    提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。