A11775 | Cycles in product
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Consider a tree (that is, an undirected connected graph without loops) $T_1$ and a tree $T_2$ . Let's define their cartesian product $T_1 \times T_2$ in a following way.
Let $V$ be the set of vertices in $T_1$ and $U$ be the set of vertices in $T_2$ .
Then the set of vertices of graph $T_1 \times T_2$ is $V \times U$ , that is, a set of ordered pairs of vertices, where the first vertex in pair is from $V$ and the second — from $U$ .
Let's draw the following edges:
- Between $(v, u_1)$ and $(v, u_2)$ there is an undirected edge, if $u_1$ and $u_2$ are adjacent in $U$ .
- Similarly, between $(v_1, u)$ and $(v_2, u)$ there is an undirected edge, if $v_1$ and $v_2$ are adjacent in $V$ .
Please see the notes section for the pictures of products of trees in the sample tests.
Let's examine the graph $T_1 \times T_2$ . How much cycles (not necessarily simple) of length $k$ it contains? Since this number can be very large, print it modulo $998244353$ .
The sequence of vertices $w_1$ , $w_2$ , ..., $w_k$ , where $w_i \in V \times U$ called cycle, if any neighboring vertices are adjacent and $w_1$ is adjacent to $w_k$ . Cycles that differ only by the cyclic shift or direction of traversal are still considered different.
Let $V$ be the set of vertices in $T_1$ and $U$ be the set of vertices in $T_2$ .
Then the set of vertices of graph $T_1 \times T_2$ is $V \times U$ , that is, a set of ordered pairs of vertices, where the first vertex in pair is from $V$ and the second — from $U$ .
Let's draw the following edges:
- Between $(v, u_1)$ and $(v, u_2)$ there is an undirected edge, if $u_1$ and $u_2$ are adjacent in $U$ .
- Similarly, between $(v_1, u)$ and $(v_2, u)$ there is an undirected edge, if $v_1$ and $v_2$ are adjacent in $V$ .
Please see the notes section for the pictures of products of trees in the sample tests.
Let's examine the graph $T_1 \times T_2$ . How much cycles (not necessarily simple) of length $k$ it contains? Since this number can be very large, print it modulo $998244353$ .
The sequence of vertices $w_1$ , $w_2$ , ..., $w_k$ , where $w_i \in V \times U$ called cycle, if any neighboring vertices are adjacent and $w_1$ is adjacent to $w_k$ . Cycles that differ only by the cyclic shift or direction of traversal are still considered different.
输入格式
First line of input contains three integers — $n_1$ , $n_2$ and $k$ ( $2 \le n_1, n_2 \le 4000$ , $2 \le k \le 75$ ) — number of vertices in the first tree, number of vertices in the second tree and the cycle length respectively.
Then follow $n_1 - 1$ lines describing the first tree. Each of this lines contains two integers — $v_i, u_i$ ( $1 \le v_i, u_i \le n_1$ ), which define edges of the first tree.
Then follow $n_2 - 1$ lines, which describe the second tree in the same format.
It is guaranteed, that given graphs are trees.
Then follow $n_1 - 1$ lines describing the first tree. Each of this lines contains two integers — $v_i, u_i$ ( $1 \le v_i, u_i \le n_1$ ), which define edges of the first tree.
Then follow $n_2 - 1$ lines, which describe the second tree in the same format.
It is guaranteed, that given graphs are trees.
输出格式
Print one integer — number of cycles modulo $998244353$ .
输入输出样例
输入 #1
2 2 2 1 2 1 2
输出 #1
8
输入 #2
2 2 4 1 2 1 2
输出 #2
32
输入 #3
2 3 4 1 2 1 2 1 3
输出 #3
70
输入 #4
4 2 2 1 2 1 3 1 4 1 2
输出 #4
20
The following three pictures illustrate graph, which are products of the trees from sample tests.
In the first example, the list of cycles of length $2$ is as follows:
- «AB», «BA»
- «BC», «CB»
- «AD», «DA»
- «CD», «DC»

In the first example, the list of cycles of length $2$ is as follows:
- «AB», «BA»
- «BC», «CB»
- «AD», «DA»
- «CD», «DC»

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted