Codeforces Round 908 (Div. 1)
E
Cacti Symphony
Codeforces
3500
原题
← D→
翻译中…

You are given an undirected connected graph in which any two distinct simple cycles do not have common vertices. Since the graph can be very large, it is given to you in a compressed form: for each edge, you are also given a number $d$, which indicates that there are $d$ additional vertices on this edge.

翻译中…

You need to assign a weight to each vertex and each edge of the graph — an integer from $1$ to $3$.

翻译中…

An edge of the graph is called good if the bitwise XOR of the weights of its adjacent vertices is not equal to $0$ and not equal to the weight of that edge.

翻译中…

Similarly, a vertex of the graph is called good if the bitwise XOR of the weights of its adjacent edges is not equal to $0$ and not equal to the weight of that vertex.

翻译中…

You need to determine how many ways there are to assign weights to the vertices and edges of the graph so that all vertices and edges are good. Since the answer can be quite large, you need to calculate the remainder of the answer divided by $998\,244\,353$.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ — the number of vertices and the number of edges in the graph ($2 \le n \le 5 \cdot 10^5$, $n - 1 \le m \le 10^6$).

翻译中…

Each of the next $m$ lines contains three integers $a_i, b_i$, and $d_i$ ($1 \le a_i, b_i \le n$, $a_i \ne b_i$, $0 \le d_i \le 10^9$), indicating that there is an edge in the graph connecting vertices $a_i$ and $b_i$. Additionally, on this edge, there are $d_i$ additional vertices. It is guaranteed that the given graph is connected, there are no multiple edges, loops, and any two distinct simple cycles of the graph do not have common vertices.

翻译中…

Output

翻译中…

Output a single integer — the answer to the problem modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test, the graph is a simple cycle of $3$ vertices. It can be shown, that there are exactly $12$ ways to assign weights, to make all vertexes and edges good.

翻译中…

In the second test, the graph has the form of two simple cycles of $3$ vertices connected by an edge. It can be shown that for such a graph there are no ways to arrange weights so that all vertices and edges are good.

翻译中…

样例

Input #1
3 3
1 2 0
2 3 0
3 1 0
Output #1
12
InputCopy OutputCopy
Input #2
6 7
1 2 0
2 3 0
3 1 0
4 5 0
5 6 0
6 4 0
4 3 0
Output #2
0
InputCopy OutputCopy
Input #3
2 1
2 1 777
Output #3
0
InputCopy OutputCopy
Input #4
3 3
1 2 0
2 3 110850709
3 1 1000000000
Output #4
179179178
InputCopy OutputCopy
题目信息
题号
1893E
时间限制
3 s
内存限制
512 MB
标签
组合数学
DFS 及类似
动态规划
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。