302855: CF553C. Love Triangles
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Love Triangles
题意翻译
给出$n$个点,要求构造合法的完全图,已经给出了一些边。 边有爱边和恨边,其中任意三个点,连成的边合法的组合有爱爱爱,爱恨恨。 问符合要求的完全图的数量,对$1e9+7$取模 $n\leq 10^5$ 感谢@Tyher 提供的翻译题目描述
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 $ .输入输出格式
输入格式
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} $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF553C/26e54e6b3b9751cc71b106d519c04019ef62f5b4.png)). 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