A9902 | Love Triangles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has $n$ characters. The characters are labeled from $1$ to $n$ . Every pair of two characters can either mutually love each other or mutually hate each other (there is no neutral state).
You hate love triangles (A-B are in love and B-C are in love, but A-C hate each other), and you also hate it when nobody is in love. So, considering any three characters, you will be happy if exactly one pair is in love (A and B love each other, and C hates both A and B), or if all three pairs are in love (A loves B, B loves C, C loves A).
You are given a list of $m$ known relationships in the anime. You know for sure that certain pairs love each other, and certain pairs hate each other. You're wondering how many ways you can fill in the remaining relationships so you are happy with every triangle. Two ways are considered different if two characters are in love in one way but hate each other in the other. Print this count modulo $1000000007$ .
You hate love triangles (A-B are in love and B-C are in love, but A-C hate each other), and you also hate it when nobody is in love. So, considering any three characters, you will be happy if exactly one pair is in love (A and B love each other, and C hates both A and B), or if all three pairs are in love (A loves B, B loves C, C loves A).
You are given a list of $m$ known relationships in the anime. You know for sure that certain pairs love each other, and certain pairs hate each other. You're wondering how many ways you can fill in the remaining relationships so you are happy with every triangle. Two ways are considered different if two characters are in love in one way but hate each other in the other. Print this count modulo $1000000007$ .
输入格式
The first line of input will contain two integers $n,m$ ( $3<=n<=100000$ , $0<=m<=100000$ ).
The next $m$ lines will contain the description of the known relationships. The $i$ -th line will contain three integers $a_{i},b_{i},c_{i}$ . If $c_{i}$ is 1, then $a_{i}$ and $b_{i}$ are in love, otherwise, they hate each other ( $1<=a_{i},b_{i}<=n$ , $a_{i}≠b_{i}$ , ).
Each pair of people will be described no more than once.
The next $m$ lines will contain the description of the known relationships. The $i$ -th line will contain three integers $a_{i},b_{i},c_{i}$ . If $c_{i}$ is 1, then $a_{i}$ and $b_{i}$ are in love, otherwise, they hate each other ( $1<=a_{i},b_{i}<=n$ , $a_{i}≠b_{i}$ , ).
Each pair of people will be described no more than once.
输出格式
Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo $1000000007$ .
输入输出样例
输入 #1
3 0
输出 #1
4
输入 #2
4 4 1 2 1 2 3 1 3 4 0 4 1 0
输出 #2
1
输入 #3
4 4 1 2 1 2 3 1 3 4 0 4 1 1
输出 #3
0
In the first sample, the four ways are to:
- Make everyone love each other
- Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other.
- Make everyone love each other
- Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted