跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1056. Xor-matic Number of the Graph

    ID: 1062 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>位运算图论数学数论数据结构挑战难度共享题库Codeforces英文题面题目来源题面语言

Xor-matic Number of the Graph

题目描述

G. Xor-matic Number of the Graph
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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<vn 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 109+7 of the values of s over all interesting triples.

Input

The first line of the input contains two integers n andm (1≤n≤100000, 0≤m≤200000)− numbers of vertices and edges in the given graph.

The follow m lines contain three integers ui, vi andti (1≤ui,vin, 0≤ti≤1018, uivi)− 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 109+7.

Examples
Input
4 4
1 2 1
1 3 2
2 3 3
3 4 1
Output
12
Input
4 4
1 2 1
2 3 2
3 4 4
4 1 8
Output
90
Input
8 6
1 2 2
2 3 1
2 4 4
4 5 5
4 6 3
7 8 5
Output
62
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.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 515 题。保留原作者与原赛事署名。