CF1236F.Alice and the Cactus

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice recently found some cactuses growing near her house! After several months, more and more cactuses appeared and soon they blocked the road. So Alice wants to clear them.

A cactus is a connected undirected graph. No edge of this graph lies on more than one simple cycle. Let's call a sequence of different nodes of the graph x1,x2,…,xkx_1, x_2, \ldots, x_k a simple cycle, if k≥3k \geq 3 and all pairs of nodes x1x_1 and x2x_2, x2x_2 and x3x_3, …\ldots, xk−1x_{k-1} and xkx_k, xkx_k and x1x_1 are connected with edges. Edges (x1,x2)(x_1, x_2), (x2,x3)(x_2, x_3), …\ldots, (xk−1,xk)(x_{k-1}, x_k), (xk,x1)(x_k, x_1) lies on this simple cycle.

There are so many cactuses, so it seems hard to destroy them. But Alice has magic. When she uses the magic, every node of the cactus will be removed independently with the probability 12\frac{1}{2}. When a node is removed, the edges connected to it are also removed.

Now Alice wants to test her magic. She has picked a cactus with nn nodes and mm edges. Let X[S]X[S] (where SS is a subset of the removed nodes) be the number of connected components in the remaining graph after removing nodes of set SS. Before she uses magic, she wants to know the variance of random variable XX, if all nodes of the graph have probability 12\frac{1}{2} to be removed and all nn of these events are independent. By the definition the variance is equal to E[(X−E[X])2]E[(X - E[X])^2], where E[X]E[X] is the expected value of XX. Help her and calculate this value by modulo 109+710^9+7.

Formally, let M=109+7M = 10^9 + 7 (a prime number). It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, find such an integer xx that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

爱丽丝最近在她家附近发现了一些仙人掌!几个月后,越来越多的仙人掌冒了出来,很快便堵塞了道路。因此,爱丽丝想要清除它们。

仙人掌图 是一个连通的无向图,其中任意一条边至多属于一个简单环。我们称图中一列互不相同的节点 x1,x2,…,xkx_1, x_2, \ldots, x_k 为一个简单环,当且仅当 k≥3k \geq 3,且所有相邻节点对 x1x_1 与 x2x_2、x2x_2 与 x3x_3、…\ldots、xk−1x_{k-1} 与 xkx_k、xkx_k 与 x1x_1 均由边相连。这些边 (x1,x2)(x_1, x_2)、(x2,x3)(x_2, x_3)、…\ldots、(xk−1,xk)(x_{k-1}, x_k)、(xk,x1)(x_k, x_1) 均属于该简单环。

仙人掌数量众多,似乎难以全部摧毁。但爱丽丝拥有魔法:当她施放魔法时,仙人掌图中的每个节点将独立地以概率 12\frac{1}{2} 被移除;一旦某个节点被移除,所有与其相连的边也将一并被移除。

现在爱丽丝想测试她的魔法。她已选定一棵含 nn 个节点和 mm 条边的仙人掌图。令 X[S]X[S](其中 SS 是被移除节点的子集)表示从原图中移除集合 SS 中所有节点后,剩余图的连通分量数目。在施放魔法前,她希望知道随机变量 XX 的方差(variance)——即假设图中每个节点均以概率 12\frac{1}{2} 被移除,且这 nn 个事件相互独立时的方差。根据定义,方差为 E[(X−E[X])2]E[(X - E[X])^2],其中 E[X]E[X] 表示 XX 的期望值。请帮助她计算该值,并对 109+710^9+7 取模。

形式化地,令 M=109+7M = 10^9 + 7(一个质数)。可以证明,答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,求满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入格式

The first line contains two integers nn and mm, separated by space (1≤n≤5⋅105,n−1≤m≤5⋅1051 \leq n \leq 5 \cdot 10^5, n - 1 \leq m \leq 5 \cdot 10^5) — the number of nodes and edges in the cactus.

The following mm lines contain two numbers uu and vv each, separated by space (1≤u,v≤n,u≠v1 \leq u, v \leq n, u \neq v) meaning that there is an edge between the nodes uu and vv.

It is guaranteed that there are no loops and multiple edges in the graph and the given graph is cactus.

第一行包含两个整数 nn 和 mm,以空格分隔(1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5,n−1≤m≤5⋅105n - 1 \leq m \leq 5 \cdot 10^5)——分别表示仙人掌图中的节点数和边数。

接下来的 mm 行每行包含两个数字 uu 和 vv,以空格分隔(1≤u,v≤n1 \leq u, v \leq n,u≠vu \neq v),表示节点 uu 与节点 vv 之间存在一条边。

保证图中不存在自环和重边,且给定的图是一棵仙人掌图。

输出格式

Print one integer — the variance of the number of connected components in the remaining graph, after removing a set of nodes such that each node has probability 12\frac{1}{2} to be removed and all these events are independent. This value should be found by modulo 109+710^9+7.

输出一个整数——在以概率 12\frac{1}{2} 独立地移除每个节点后,剩余图中连通分量数量的方差。该值需对 109+710^9+7 取模。

输入输出样例

  • 输入#1

    3 3
    1 2
    2 3
    1 3

    输出#1

    984375007
  • 输入#2

    5 6
    1 2
    2 3
    1 3
    3 4
    4 5
    3 5

    输出#2

    250000002

说明/提示

In the first sample, the answer is 764\frac{7}{64}. If all nodes are removed the value of XX is equal to 00, otherwise, it is equal to 11. So, the expected value of XX is equal to 0×18+1×78=780\times\frac{1}{8}+1\times\frac{7}{8}=\frac{7}{8}. So, the variance of XX is equal to (0−78)2×18+(1−78)2×78=(78)2×18+(18)2×78=764(0 - \frac{7}{8})^2\times\frac{1}{8}+(1-\frac{7}{8})^2\times\frac{7}{8} = (\frac{7}{8})^2\times\frac{1}{8}+(\frac{1}{8})^2\times\frac{7}{8} = \frac{7}{64}.

In the second sample, the answer is 14\frac{1}{4}.

在第一个样例中,答案为 764\frac{7}{64}。若所有节点均被移除,则 XX 的值为 00;否则,XX 的值为 11。因此,XX 的期望值为 0×18+1×78=780\times\frac{1}{8}+1\times\frac{7}{8}=\frac{7}{8}。于是,XX 的方差为 (0−78)2×18+(1−78)2×78=(78)2×18+(18)2×78=764(0 - \frac{7}{8})^2\times\frac{1}{8}+(1-\frac{7}{8})^2\times\frac{7}{8} = (\frac{7}{8})^2\times\frac{1}{8}+(\frac{1}{8})^2\times\frac{7}{8} = \frac{7}{64}。

在第二个样例中,答案为 14\frac{1}{4}。

输入解题思路,AI测评打分。不知道怎么写?

首页