Under construction

Still being built. Things may change

Tree

Time limit1sMemory limit512 MB

Summary
Count labelled trees on N vertices that contain all M given edges, modulo 1e9+7, with N up to 1e9.
Level

Medium7 of 10

Topics
Combinatorics, Union-find, Math, Graph
Solved
No attempts yet

Problem

A tree is an undirected graph in which exactly one path connects any two vertices. Equivalently, it is a graph that is connected and has no cycle.

Count the trees you can build on NN distinguishable vertices. Number the vertices from 11 to NN, and two trees are different when their edges join different pairs of vertices. For N=4N = 4 there are 16 trees, shown below.

The 16 trees on 4 labelled vertices

Write a program that counts the trees on NN distinguishable vertices that contain all MM given edges.

Input

The first line contains two integers separated by a space: the number of vertices NN and the number of edges MM that the tree must contain. Each of the next MM lines contains the two endpoints aa and bb (1≤a,b≤N1 \le a, b \le N) of a required edge. The values aa and bb are different, and no edge is given twice. It may be impossible to build a tree that contains every given edge.

1≤N≤1091 \le N \le 10^9, 0≤M≤1050 \le M \le 10^5

Output

Print the number of trees that contain every given edge. The number can be very large, so print it modulo 1 000 000 0071\,000\,000\,007.

Hint

The trees on 4 labelled vertices with the edge between vertex 1 and vertex 2 in red

The picture colours the edge between vertex 1 and vertex 2 red. With 4 vertices, only 8 trees contain that edge.

Examples2

  1. Example 1

    Input
    4 0
    
    Expected output
    16
    
  2. Example 2

    Input
    4 1
    1 2
    
    Expected output
    8