No.1843 Tree ANDistance
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.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もしくは右上の雲マークをクリックしてアカウントを作成してください。
tatyam
nok0