This page is still under construction.

Parts of this page are still being built. What you see may change.

Spanning Tree

Time limit1sMemory limit128 MB

Summary
Count the minimum spanning trees of a connected weighted multigraph modulo 1000003, where any weight class has at most 4 edges.
Level

Hard8 of 10

Topics
Minimum spanning tree, Union-find, Combinatorics
Solved
No attempts yet

Problem

You are given a connected weighted multigraph. Write a program that finds the number of minimum spanning trees of this graph.

Because it is a multigraph, it may contain loops (edges from a vertex to itself), and there may be several edges between the same pair of vertices.

In the given graph, at most 44 edges share the same weight.

Input

The first line contains the number of vertices NN and the number of edges MM. (1≤N≤5×1041 \le N \le 5 \times 10^4, 1≤M≤1051 \le M \le 10^5) The vertices are numbered from 11 to NN.

Each of the next MM lines contains three integers aa, bb, and ww, separated by spaces. (1≤a,b≤N1 \le a, b \le N, 1≤w≤2301 \le w \le 2^{30}) This means there is an edge of weight ww connecting vertex aa and vertex bb.

Output

On the first line, print the number of minimum spanning trees modulo 10000031000003.

Examples3

  1. Example 1

    Input
    3 5
    1 2 6
    1 2 6
    2 3 6
    3 1 6
    3 3 8
    
    Expected output
    5
    
  2. Example 2

    Input
    2 2
    1 2 4
    1 2 4
    
    Expected output
    2
    
  3. Example 3

    Input
    3 3
    1 2 1
    2 3 1
    1 3 1
    
    Expected output
    3