A8416 | Clues
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues $A$ and $B$ and the direct link between clues $B$ and $A$ is the same thing. No more than one direct link can exist between two clues.
Of course Sherlock is able to find direct links between all clues. But it will take too much time and the criminals can use this extra time to hide. To solve the crime, Sherlock needs each clue to be linked to all other clues (maybe not directly, via some other clues). Clues $A$ and $B$ are considered linked either if there is a direct link between them or if there is a direct link between $A$ and some other clue $C$ which is linked to $B$ .
Sherlock Holmes counted the minimum number of additional direct links that he needs to find to solve the crime. As it turns out, it equals $T$ .
Please count the number of different ways to find exactly $T$ direct links between the clues so that the crime is solved in the end. Two ways to find direct links are considered different if there exist two clues which have a direct link in one way and do not have a direct link in the other way.
As the number of different ways can turn out rather big, print it modulo $k$ .
Of course Sherlock is able to find direct links between all clues. But it will take too much time and the criminals can use this extra time to hide. To solve the crime, Sherlock needs each clue to be linked to all other clues (maybe not directly, via some other clues). Clues $A$ and $B$ are considered linked either if there is a direct link between them or if there is a direct link between $A$ and some other clue $C$ which is linked to $B$ .
Sherlock Holmes counted the minimum number of additional direct links that he needs to find to solve the crime. As it turns out, it equals $T$ .
Please count the number of different ways to find exactly $T$ direct links between the clues so that the crime is solved in the end. Two ways to find direct links are considered different if there exist two clues which have a direct link in one way and do not have a direct link in the other way.
As the number of different ways can turn out rather big, print it modulo $k$ .
输入格式
The first line contains three space-separated integers $n,m,k$ ( $1<=n<=10^{5},0<=m<=10^{5}$ , $1<=k<=10^{9}$ ) — the number of clues, the number of direct clue links that Holmes has already found and the divisor for the modulo operation.
Each of next $m$ lines contains two integers $a$ and $b$ ( $1<=a,b<=n,a≠b$ ), that represent a direct link between clues. It is guaranteed that any two clues are linked by no more than one direct link. Note that the direct links between the clues are mutual.
Each of next $m$ lines contains two integers $a$ and $b$ ( $1<=a,b<=n,a≠b$ ), that represent a direct link between clues. It is guaranteed that any two clues are linked by no more than one direct link. Note that the direct links between the clues are mutual.
输出格式
Print the single number — the answer to the problem modulo $k$ .
输入输出样例
输入 #1
2 0 1000000000
输出 #1
1
输入 #2
3 0 100
输出 #2
3
输入 #3
4 1 1000000000 1 4
输出 #3
8
The first sample only has two clues and Sherlock hasn't found any direct link between them yet. The only way to solve the crime is to find the link.
The second sample has three clues and Sherlock hasn't found any direct links between them. He has to find two of three possible direct links between clues to solve the crime — there are $3$ ways to do it.
The third sample has four clues and the detective has already found one direct link between the first and the fourth clue. There are $8$ ways to find two remaining clues to solve the crime.
The second sample has three clues and Sherlock hasn't found any direct links between them. He has to find two of three possible direct links between clues to solve the crime — there are $3$ ways to do it.
The third sample has four clues and the detective has already found one direct link between the first and the fourth clue. There are $8$ ways to find two remaining clues to solve the crime.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted