A849 | Counting Graphs--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Bessie has a connected, undirected graph $G$ with $N$ vertices labeled
$1\ldots N$ and $M$ edges ($2\le N\le 10^2, N-1\le M\le \frac{N^2+N}{2}$). $G$
may contain self-loops (edges from nodes back to themselves), but no parallel
edges (multiple edges connecting the same endpoints).
Let $f_G(a,b)$ be a boolean function that evaluates to true if there exists a
path from vertex $1$ to vertex $a$ that traverses exactly $b$ edges for each
$1\le a\le N$ and $0\le b$, and false otherwise. If an edge is traversed
multiple times, it is included that many times in the count.
Elsie wants to copy Bessie. In particular, she wants to construct an
undirected graph $G'$ such that $f_{G'}(a,b)=f_G(a,b)$ for all $a$ and $b$.
Your job is to count the number of distinct graphs $G'$ that Elsie may create,
modulo $10^9+7$. As with $G$, $G'$ may contain self-loops but no parallel
edges (meaning that there are $2^{\frac{N^2+N}{2}}$ distinct graphs on $N$
labeled vertices in total).
Each input contains $T$ ($1\le T\le \frac{10^5}{4}$) test cases that should be
solved independently. It is guaranteed that the sum of $N^2$ over all test
cases does not exceed $10^5$.
$1\ldots N$ and $M$ edges ($2\le N\le 10^2, N-1\le M\le \frac{N^2+N}{2}$). $G$
may contain self-loops (edges from nodes back to themselves), but no parallel
edges (multiple edges connecting the same endpoints).
Let $f_G(a,b)$ be a boolean function that evaluates to true if there exists a
path from vertex $1$ to vertex $a$ that traverses exactly $b$ edges for each
$1\le a\le N$ and $0\le b$, and false otherwise. If an edge is traversed
multiple times, it is included that many times in the count.
Elsie wants to copy Bessie. In particular, she wants to construct an
undirected graph $G'$ such that $f_{G'}(a,b)=f_G(a,b)$ for all $a$ and $b$.
Your job is to count the number of distinct graphs $G'$ that Elsie may create,
modulo $10^9+7$. As with $G$, $G'$ may contain self-loops but no parallel
edges (meaning that there are $2^{\frac{N^2+N}{2}}$ distinct graphs on $N$
labeled vertices in total).
Each input contains $T$ ($1\le T\le \frac{10^5}{4}$) test cases that should be
solved independently. It is guaranteed that the sum of $N^2$ over all test
cases does not exceed $10^5$.
输入格式
The first line of the input contains $T$, the number of test cases.
The first line of each test case contains the integers $N$ and $M$.
The next $M$ lines of each test case each contain two integers $x$ and $y$
($1\le x\le y\le N$), denoting that there exists an edge between $x$ and $y$
in $G$.
Consecutive test cases are separated by newlines for readability.
The first line of each test case contains the integers $N$ and $M$.
The next $M$ lines of each test case each contain two integers $x$ and $y$
($1\le x\le y\le N$), denoting that there exists an edge between $x$ and $y$
in $G$.
Consecutive test cases are separated by newlines for readability.
输出格式
For each test case, the number of distinct $G'$ modulo $10^9+7$ on a new line.
输入输出样例
输入 #1
1 5 4 1 2 2 3 1 4 3 5
输出 #1
3
In the first test case, $G'$ could equal $G$ or one of the two following
graphs:
5 4
1 2
1 4
3 4
3 5
5 5
1 2
2 3
1 4
3 4
3 5
graphs:
5 4
1 2
1 4
3 4
3 5
5 5
1 2
2 3
1 4
3 4
3 5
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted