CF997D.Cycles in product
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider a tree (that is, an undirected connected graph without loops) T1 and a tree T2 . Let's define their cartesian product T1×T2 in a following way.
Let V be the set of vertices in T1 and U be the set of vertices in T2 .
Then the set of vertices of graph T1×T2 is V×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,u1) and (v,u2) there is an undirected edge, if u1 and u2 are adjacent in U .
- Similarly, between (v1,u) and (v2,u) there is an undirected edge, if v1 and v2 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 T1×T2 . 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 w1 , w2 , ..., wk , where wi∈V×U called cycle, if any neighboring vertices are adjacent and w1 is adjacent to wk . Cycles that differ only by the cyclic shift or direction of traversal are still considered different.
输入格式
First line of input contains three integers — n1 , n2 and k ( 2≤n1,n2≤4000 , 2≤k≤75 ) — number of vertices in the first tree, number of vertices in the second tree and the cycle length respectively.
Then follow n1−1 lines describing the first tree. Each of this lines contains two integers — vi,ui ( 1≤vi,ui≤n1 ), which define edges of the first tree.
Then follow n2−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»