CF869D.The Overdosing Ubiquity
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
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 n nodes numbered from 1 to n. The node numbered 1 is the root, and the parent of the i-th (2 ≤ i ≤ n) node is
. Note that, however, all edges in the tree are undirected.
Koyomi adds m 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 + 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.
正义的根本前提并非正确,而是强大。正因如此,正义永远是胜利者。
灰烬群蜂。小夜未深知这一点。
根据其天性,蜜蜂栖息于一棵树中。更具体地说,这是一棵具有 n 个节点的完全二叉树,节点编号为 1 至 n。编号为 1 的节点是根节点,而第 i 个节点(2≤i≤n)的父节点为
。注意:树中的所有边均为无向边。
小夜未向该树额外添加了 m 条无向边,以增加复杂性来迷惑蜜蜂。而你的任务是计算所得图中简单路径的数量,并对 109+7 取模。简单路径是指由相邻节点与无向边交替构成的序列,该序列以节点开始并以节点结束,且其中任意节点至多出现一次。请注意:按此定义,单个节点本身也被视为一条有效的简单路径。请参阅下方示例及说明以获取具体实例。
输入格式
The first line of input contains two space-separated integers n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 4) — the number of nodes in the tree and the number of extra edges respectively.
The following m lines each contains two space-separated integers u and v (1 ≤ u, v ≤ n, u ≠ v) — describing an undirected extra edge whose endpoints are u and v.
Note that there may be multiple edges between nodes in the resulting graph.
输入的第一行包含两个用空格分隔的整数 n 和 m(1 ≤ n ≤ 109,0 ≤ m ≤ 4)—— 分别表示树中节点的数量和额外边的数量。
接下来的 m 行,每行包含两个用空格分隔的整数 u 和 v(1 ≤ u, v ≤ n,u = v)—— 描述一条无向的额外边,其端点为 u 和 v。
注意:在最终得到的图中,节点之间可能存在多条边。
输出格式
Output one integer — the number of simple paths in the resulting graph, modulo 109 + 7.
输出一个整数——结果图中简单路径的数量,对 109+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); (2); (3); (1, 2); (2, 1); (1, 3); (3, 1); (2, 1, 3); (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, 2); (1, 2, 3); (1, 3); (1, 3, 2); and similarly for paths starting with 2 and 3. (5 × 3 = 15 paths in total.)
In the third example, the paths are: (1); (2); any undirected edge connecting the two nodes travelled in either direction. (2 + 5 × 2 = 12 paths in total.)
在第一个例子中,路径有:(1);(2);(3);(1, 2);(2, 1);(1, 3);(3, 1);(2, 1, 3);(3, 1, 2)。(为清晰起见,省略了节点之间的边,因为本例中不存在重边。)
在第二个例子中,路径有:(1);(1, 2);(1, 2, 3);(1, 3);(1, 3, 2);以及以 2 和 3 为起点的类似路径。(共 5 × 3 = 15 条路径。)
在第三个例子中,路径有:(1);(2);以及任意一条连接这两个节点的无向边(可沿任一方向遍历)。(共 2 + 5 × 2 = 12 条路径。)
输入解题思路,AI测评打分。不知道怎么写?