CF997D.Cycles in product

省选/NOI-

通过率:0%

时间限制:7.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider a tree (that is, an undirected connected graph without loops) T1T_1 and a tree T2T_2. Let's define their cartesian product T1×T2T_1 \times T_2 in a following way.

Let VV be the set of vertices in T1T_1 and UU be the set of vertices in T2T_2.

Then the set of vertices of graph T1×T2T_1 \times T_2 is V×UV \times U, that is, a set of ordered pairs of vertices, where the first vertex in pair is from VV and the second — from UU.

Let's draw the following edges:

  • Between (v,u1)(v, u_1) and (v,u2)(v, u_2) there is an undirected edge, if u1u_1 and u2u_2 are adjacent in UU.
  • Similarly, between (v1,u)(v_1, u) and (v2,u)(v_2, u) there is an undirected edge, if v1v_1 and v2v_2 are adjacent in VV.

Please see the notes section for the pictures of products of trees in the sample tests.

Let's examine the graph T1×T2T_1 \times T_2. How much cycles (not necessarily simple) of length kk it contains? Since this number can be very large, print it modulo 998244353998244353.

The sequence of vertices w1w_1, w2w_2, ..., wkw_k, where wi∈V×Uw_i \in V \times U called cycle, if any neighboring vertices are adjacent and w1w_1 is adjacent to wkw_k. Cycles that differ only by the cyclic shift or direction of traversal are still considered different.

考虑两棵树(即无环的无向连通图)T1T_1 与 T2T_2。我们如下定义它们的笛卡尔积 T1×T2T_1 \times T_2。

设 VV 为 T1T_1 的顶点集,UU 为 T2T_2 的顶点集。

则图 T1×T2T_1 \times T_2 的顶点集为 V×UV \times U,即所有有序顶点对构成的集合,其中每对的第一个顶点属于 VV,第二个顶点属于 UU。

我们添加如下边:

  • 若 u1u_1 与 u2u_2 在 UU 中相邻,则在 (v,u1)(v, u_1) 与 (v,u2)(v, u_2) 之间连一条无向边;
  • 类似地,若 v1v_1 与 v2v_2 在 VV 中相邻,则在 (v1,u)(v_1, u) 与 (v2,u)(v_2, u) 之间连一条无向边。

有关样例测试中树的笛卡尔积的示意图,请参见“注释”部分。

现在考察图 T1×T2T_1 \times T_2:它包含多少条长度为 kk 的环(不一定是简单环)?由于该数目可能非常大,请输出其对 998244353998244353 取模的结果。

顶点序列 w1,w2,…,wkw_1, w_2, \dots, w_k(其中每个 wi∈V×Uw_i \in V \times U)称为一个环,当且仅当任意两个相邻顶点均邻接,且 w1w_1 与 wkw_k 邻接。仅因循环移位或遍历方向不同而产生的环仍被视为不同的环。

输入格式

First line of input contains three integers — n1n_1, n2n_2 and kk (2≤n1,n2≤40002 \le n_1, n_2 \le 4000, 2≤k≤752 \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 n1−1n_1 - 1 lines describing the first tree. Each of this lines contains two integers — vi,uiv_i, u_i (1≤vi,ui≤n11 \le v_i, u_i \le n_1), which define edges of the first tree.

Then follow n2−1n_2 - 1 lines, which describe the second tree in the same format.

It is guaranteed, that given graphs are trees.

输入的第一行包含三个整数 — n1n_1、n2n_2 和 kk(2≤n1,n2≤40002 \le n_1, n_2 \le 4000,2≤k≤752 \le k \le 75),分别表示第一棵树的顶点数、第二棵树的顶点数以及环的长度。

接下来是 n1−1n_1 - 1 行,用于描述第一棵树。每行包含两个整数 viv_i、uiu_i(1≤vi,ui≤n11 \le v_i, u_i \le n_1),表示第一棵树的一条边。

随后是 n2−1n_2 - 1 行,以相同格式描述第二棵树。

保证所给图均为树。

输出格式

Print one integer — number of cycles modulo 998244353998244353.

输出一个整数——环的数量对 998244353998244353 取模的结果。

输入输出样例

  • 输入#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 22 is as follows:

  • «AB», «BA»
  • «BC», «CB»
  • «AD», «DA»
  • «CD», «DC»

以下三张图片展示了图结构,它们分别是样例测试中树的乘积。

在第一个例子中,长度为 22 的环的列表如下:

  • «AB»、«BA»
  • «BC»、«CB»
  • «AD»、«DA»
  • «CD»、«DC»

输入解题思路,AI测评打分。不知道怎么写?

首页