A16338 | Cacti Symphony
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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](https://en.wikipedia.org/wiki/Exclusive_or) 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](https://en.wikipedia.org/wiki/Exclusive_or) 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$ .
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](https://en.wikipedia.org/wiki/Exclusive_or) 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](https://en.wikipedia.org/wiki/Exclusive_or) 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$ .
输入格式
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.
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 a single integer — the answer to the problem modulo $998\,244\,353$ .
输入输出样例
输入 #1
3 3 1 2 0 2 3 0 3 1 0
输出 #1
12
输入 #2
6 7 1 2 0 2 3 0 3 1 0 4 5 0 5 6 0 6 4 0 4 3 0
输出 #2
0
输入 #3
2 1 2 1 777
输出 #3
0
输入 #4
3 3 1 2 0 2 3 110850709 3 1 1000000000
输出 #4
179179178
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted