CF553C.Love Triangles
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 1 000 000 007.
有许多动漫以“爱情三角”为主题:爱丽丝爱鲍勃,查理也爱鲍勃,但爱丽丝讨厌查理。你正在构思一部拥有 n 个角色的动漫。这些角色编号为 1 到 n。任意两个角色之间要么彼此相爱,要么彼此憎恨(不存在中立状态)。
你讨厌“爱情三角”(即:A 与 B 相爱、B 与 C 相爱,但 A 与 C 相互憎恨),同时也讨厌“无人相爱”的情形。因此,对任意三个角色,只有当恰好有一对彼此相爱(例如:A 与 B 相爱,而 C 同时憎恨 A 和 B),或三对全部彼此相爱(即:A 爱 B、B 爱 C、C 爱 A)时,你才会感到满意。
现在给出该动漫中已知的 m 对关系。你确切地知道某些角色对彼此相爱,而另一些角色对彼此憎恨。你想知道:有多少种方式可以填补剩余未知的关系,使得每一个由三个角色构成的三角都令你满意?若在两种方案中,某一对角色在一种方案中相爱、而在另一种方案中相互憎恨,则认为这两种方案不同。请输出该数目对 1000000007 取模的结果。
输入格式
The first line of input will contain two integers n, m (3 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000).
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.
输入的第一行包含两个整数 n 和 m(3≤n≤100000,0≤m≤100000)。
接下来的 m 行描述已知的关系。第 i 行包含三个整数 ai,bi,ci。若 ci=1,则 ai 与 bi 彼此相爱;否则,他们彼此憎恨(1≤ai,bi≤n,ai=bi,
)。
每一对人物至多被描述一次。
输出格式
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 1 000 000 007.
输出一个整数,表示填满剩余数对的方式数目,使得你对每个三角形都感到满意,结果对 1 000 000 007 取模。
输入输出样例
输入#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.
在第一个样例中,共有四种方案:
- 让所有人彼此相爱;
- 让 1 和 2 彼此相爱,且 3 憎恨 1 和 2(对称地,由此可得到 3 种方案)。
在第二个样例中,唯一可行的方案是让 1 和 3 彼此相爱,且 2 和 4 彼此憎恨。
输入解题思路,AI测评打分。不知道怎么写?