A8712 | Cactus
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ ).
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$ ).
输入格式
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$ .
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$ .
输出格式
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$ ).
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted