Codeforces Round 143 (Div. 2)
E
Cactus
Codeforces
2100
原题
← D→
翻译中…

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 $*v*_{1}, *v*_{2}, ..., *v*_{*t*}$ $(*t* > 2)$, such that for any $*i*$ $(1 ≤ *i* < *t*)$ exists an edge between vertices $*v*_{*i*}$ and $*v*_{*i* + 1}$, and also exists an edge between vertices $*v*_{1}$ and $*v*_{*t*}$.

翻译中…

A simple path in a undirected graph is a sequence of not necessarily distinct vertices $*v*_{1}, *v*_{2}, ..., *v*_{*t*}$ $(*t* > 0)$, such that for any $*i*$ $(1 ≤ *i* < *t*)$ exists an edge between vertices $*v*_{*i*}$ and $*v*_{*i* + 1}$ and furthermore each edge occurs no more than once. We'll say that a simple path $*v*_{1}, *v*_{2}, ..., *v*_{*t*}$ starts at vertex $*v*_{1}$ and ends at vertex $*v*_{*t*}$.

翻译中…

You've got a graph consisting of $*n*$ vertices and $*m*$ edges, that is a vertex cactus. Also, you've got a list of $*k*$ pairs of interesting vertices $*x*_{*i*}, *y*_{*i*}$, for which you want to know the following information — the number of distinct simple paths that start at vertex $*x*_{*i*}$ and end at vertex $*y*_{*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 $1000000007$ ($10^{9} + 7$).

翻译中…

Input

翻译中…

The first line contains two space-separated integers $*n*, *m*$ $(2 ≤ *n* ≤ 10^{5}; 1 ≤ *m* ≤ 10^{5})$ — the number of vertices and edges in the graph, correspondingly. Next $*m*$ lines contain the description of the edges: the $*i*$-th line contains two space-separated integers $*a*_{*i*}, *b*_{*i*}$ $(1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*)$ — the indexes of the vertices connected by the $*i*$-th edge.

翻译中…

The next line contains a single integer $*k*$ $(1 ≤ *k* ≤ 10^{5})$ — the number of pairs of interesting vertices. Next $*k*$ lines contain the list of pairs of interesting vertices: the $*i*$-th line contains two space-separated numbers $*x*_{*i*}$, $*y*_{*i*}$ $(1 ≤ *x*_{*i*}, *y*_{*i*} ≤ *n*; *x*_{*i*} ≠ *y*_{*i*})$ — the indexes of interesting vertices in the $*i*$-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 $*n*$.

翻译中…

Output

翻译中…

Print $*k*$ lines: in the $*i*$-th line print a single integer — the number of distinct simple ways, starting at $*x*_{*i*}$ and ending at $*y*_{*i*}$, modulo $1000000007$ ($10^{9} + 7$).

翻译中…

样例

Input #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
Output #1
2
2
2
4
4
1
InputCopy OutputCopy
题目信息
题号
231E
时间限制
2 s
内存限制
256 MB
标签
数据结构
DFS 及类似
动态规划
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。