CF869D.The Overdosing Ubiquity

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The fundamental prerequisite for justice is not to be correct, but to be strong. That's why justice is always the victor.

The Cinderswarm Bee. Koyomi knows it.

The bees, according to their nature, live in a tree. To be more specific, a complete binary tree with nn nodes numbered from 11 to nn . The node numbered 11 is the root, and the parent of the ii -th ( 2<=i<=n2<=i<=n ) node is . Note that, however, all edges in the tree are undirected.

Koyomi adds mm extra undirected edges to the tree, creating more complication to trick the bees. And you're here to count the number of simple paths in the resulting graph, modulo 109+710^{9}+7 . A simple path is an alternating sequence of adjacent nodes and undirected edges, which begins and ends with nodes and does not contain any node more than once. Do note that a single node is also considered a valid simple path under this definition. Please refer to the examples and notes below for instances.

输入格式

The first line of input contains two space-separated integers nn and mm ( 1<=n<=1091<=n<=10^{9} , 0<=m<=40<=m<=4 ) — the number of nodes in the tree and the number of extra edges respectively.

The following mm lines each contains two space-separated integers uu and vv ( 1<=u,v<=n1<=u,v<=n , uvu≠v ) — describing an undirected extra edge whose endpoints are uu and vv .

Note that there may be multiple edges between nodes in the resulting graph.

输出格式

Output one integer — the number of simple paths in the resulting graph, modulo 109+710^{9}+7 .

输入输出样例

  • 输入#1

    3 0
    

    输出#1

    9
    
  • 输入#2

    3 1
    2 3
    

    输出#2

    15
    
  • 输入#3

    2 4
    1 2
    2 1
    1 2
    2 1
    

    输出#3

    12
    

说明/提示

In the first example, the paths are: (1)(1) ; (2)(2) ; (3)(3) ; (1,2)(1,2) ; (2,1)(2,1) ; (1,3)(1,3) ; (3,1)(3,1) ; (2,1,3)(2,1,3) ; (3,1,2)(3,1,2) . (For the sake of clarity, the edges between nodes are omitted since there are no multiple edges in this case.)

In the second example, the paths are: (1)(1) ; (1,2)(1,2) ; (1,2,3)(1,2,3) ; (1,3)(1,3) ; (1,3,2)(1,3,2) ; and similarly for paths starting with 22 and 33 . ( 5×3=155×3=15 paths in total.)

In the third example, the paths are: (1)(1) ; (2)(2) ; any undirected edge connecting the two nodes travelled in either direction. ( 2+5×2=122+5×2=12 paths in total.)

首页