Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
G
Xor-matic Number of the Graph
Codeforces
2600
原题
← F→
翻译中…

You are given an undirected graph, constisting of $*n*$ vertices and $*m*$ edges. Each edge of the graph has some non-negative integer written on it.

翻译中…

Let's call a triple $(*u*, *v*, *s*)$ interesting, if $1 ≤ *u* < *v* ≤ *n*$ and there is a path (possibly non-simple, i.e. it can visit the same vertices and edges multiple times) between vertices $*u*$ and $*v*$ such that xor of all numbers written on the edges of this path is equal to $*s*$. When we compute the value s for some path, each edge is counted in xor as many times, as it appear on this path. It's not hard to prove that there are finite number of such triples.

翻译中…

Calculate the sum over modulo $10^{9} + 7$ of the values of $*s*$ over all interesting triples.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($1 ≤ *n* ≤ 100 000$, $0 ≤ *m* ≤ 200 000$) — numbers of vertices and edges in the given graph.

翻译中…

The follow $*m*$ lines contain three integers $*u*_{*i*}$, $*v*_{*i*}$ and $*t*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$, $0 ≤ *t*_{*i*} ≤ 10^{18}$, $*u*_{*i*} ≠ *v*_{*i*}$) — vertices connected by the edge and integer written on it. It is guaranteed that graph doesn't contain self-loops and multiple edges.

翻译中…

Output

翻译中…

Print the single integer, equal to the described sum over modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In the first example the are $6$ interesting triples:

翻译中…
  1. $(1, 2, 1)$
  2. $(1, 3, 2)$
  3. $(1, 4, 3)$
  4. $(2, 3, 3)$
  5. $(2, 4, 2)$
  6. $(3, 4, 1)$
翻译中…

The sum is equal to

翻译中…

1 + 2 + 3 + 3 + 2 + 1 = 12

翻译中…

.

翻译中…

In the second example the are $12$ interesting triples:

翻译中…
  1. $(1, 2, 1)$
  2. $(2, 3, 2)$
  3. $(1, 3, 3)$
  4. $(3, 4, 4)$
  5. $(2, 4, 6)$
  6. $(1, 4, 7)$
  7. $(1, 4, 8)$
  8. $(2, 4, 9)$
  9. $(3, 4, 11)$
  10. $(1, 3, 12)$
  11. $(2, 3, 13)$
  12. $(1, 2, 14)$
翻译中…

The sum is equal to

翻译中…

1 + 2 + 3 + 4 + 6 + 7 + 8 + 9 + 11 + 12 + 13 + 14 = 90

翻译中…

.

翻译中…

样例

Input #1
4 4
1 2 1
1 3 2
2 3 3
3 4 1
Output #1
12
InputCopy OutputCopy
Input #2
4 4
1 2 1
2 3 2
3 4 4
4 1 8
Output #2
90
InputCopy OutputCopy
Input #3
8 6
1 2 2
2 3 1
2 4 4
4 5 5
4 6 3
7 8 5
Output #3
62
InputCopy OutputCopy
题目信息
题号
724G
时间限制
2 s
内存限制
256 MB
标签
位运算
图论
数学
数论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。