CF231E.Cactus

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.

A simple cycle in a undirected graph is a sequence of distinct vertices v1,v2,...,vtv_{1},v_{2},...,v_{t} (t>2) , such that for any ii (1<=i<t) exists an edge between vertices viv_{i} and vi+1v_{i+1} , and also exists an edge between vertices v1v_{1} and vtv_{t} .

A simple path in a undirected graph is a sequence of not necessarily distinct vertices v1,v2,...,vtv_{1},v_{2},...,v_{t} (t>0) , such that for any ii (1<=i<t) exists an edge between vertices viv_{i} and vi+1v_{i+1} and furthermore each edge occurs no more than once. We'll say that a simple path v1,v2,...,vtv_{1},v_{2},...,v_{t} starts at vertex v1v_{1} and ends at vertex vtv_{t} .

You've got a graph consisting of nn vertices and mm edges, that is a vertex cactus. Also, you've got a list of kk pairs of interesting vertices xi,yix_{i},y_{i} , for which you want to know the following information — the number of distinct simple paths that start at vertex xix_{i} and end at vertex yiy_{i} . We will consider two simple paths distinct if the sets of edges of the paths are distinct.

For each pair of interesting vertices count the number of distinct simple paths between them. As this number can be rather large, you should calculate it modulo 10000000071000000007 ( 109+710^{9}+7 ).

输入格式

The first line contains two space-separated integers n,mn,m (2<=n<=105; 1<=m<=105)(2<=n<=10^{5}; 1<=m<=10^{5}) — the number of vertices and edges in the graph, correspondingly. Next mm lines contain the description of the edges: the ii -th line contains two space-separated integers ai,bia_{i},b_{i} (1<=ai,bi<=n)(1<=a_{i},b_{i}<=n) — the indexes of the vertices connected by the ii -th edge.

The next line contains a single integer kk (1<=k<=105)(1<=k<=10^{5}) — the number of pairs of interesting vertices. Next kk lines contain the list of pairs of interesting vertices: the ii -th line contains two space-separated numbers xix_{i} , yiy_{i} (1<=xi,yi<=n; xiyi)(1<=x_{i},y_{i}<=n; x_{i}≠y_{i}) — the indexes of interesting vertices in the ii -th pair.

It is guaranteed that the given graph is a vertex cactus. It is guaranteed that the graph contains no loops or multiple edges. Consider the graph vertices are numbered from 1 to nn .

输出格式

Print kk lines: in the ii -th line print a single integer — the number of distinct simple ways, starting at xix_{i} and ending at yiy_{i} , modulo 10000000071000000007 ( 109+710^{9}+7 ).

输入输出样例

  • 输入#1

    10 11
    1 2
    2 3
    3 4
    1 4
    3 5
    5 6
    8 6
    8 7
    7 6
    7 9
    9 10
    6
    1 2
    3 5
    6 9
    9 2
    9 3
    9 10
    

    输出#1

    2
    2
    2
    4
    4
    1
    
首页