QOJ.ac

QOJ

Time Limit: 2.5 s Memory Limit: 1024 MB Total points: 100

#14580. Misaka Network

Statistics

题目描述

一方通行在执行任务时接入了由御坂 $10032\sim 10031+n$ 号共 $n$ 位御坂妹妹组成的临时御坂网络,每位御坂妹妹拥有一些信息,为了保证存储效率,妹妹们所拥有的信息互不相同。

临时御坂网络有两种连接 $T_1,T_2$,分别构成树形结构。

由于计算需求,妹妹们有时需要交换信息。具体地,若两位御坂妹妹间同时有两种连接,那么她们可以交换她们拥有的信息(不会保留自己原有的信息),同时会交换在 $T_2$ 中的连接(即若另一位御坂妹妹和第一位有第二种连接,那么这个连接会变成她和第二位的,反之同理)。

最后之作非常好奇妹妹们拥有信息的不同状态有多少种,两种状态不同当且仅当存在一位御坂妹妹在这两种情况中所拥有的信息不同。

她设想了若干种网络的形态,并想对于每种形态都计算出上述问题的答案(因为是设想,所以并不一定保证 $n\leq 9969$)。

御坂网络在 1s 内就计算出了答案,不过因为好玩,所以最后之作想让你帮忙验算一下,你需要告诉她状态数对 $998244353$ 取模的结果。

简要题意:

给定两棵 $n$ 个点的无根树 $T_1,T_2$,节点编号为 $1\sim n$。

有一个 $1\sim n$ 的排列 $p$,初始时 $p_i=i$,你可以进行若干次操作,每次操作选择两个点 $u,v$,满足 $u,v$ 在 $T_1$ 中相邻且 $p_u,p_v$ 在 $T_2$ 中相邻,然后交换 $p_u$ 和 $p_v$,问能得到多少种不同的 $p$,答案对 $998244353$ 取模。

$t$ 组数据。

输入格式

第一行一个整数 $t$ 表示数据组数。

接下来依次输入每组测试数据。对于每一组测试数据:

第 $1$ 行一个整数 $n$,表示临时御坂网络由 $n$ 位御坂妹妹组成。

第 $2\sim n$ 共 $n-1$ 行,每行两个整数 $u,v$ 表示 $T_1$ 中御坂 $10031+u$ 号和 $10031+v$ 号间有连接。

第 $n+1\sim 2n-1$ 共 $n-1$ 行,每行两个整数 $u,v$ 表示 $T_2$ 中御坂 $10031+u$ 号和 $10031+v$ 号间有连接。

输出格式

输出共 $t$ 行,每行一个整数,第 $i$ 行的整数表示第 $i$ 组数据的答案对 $998244353$ 取模的结果。

样例

样例输入 1
1
5
4 5
3 2
4 2
1 3
4 5
1 2
4 3
3 2

样例输出 1
8

数据范围

令 $\sum n$ 表示一个测试点内所有数据的 $n$ 的和。

对于所有数据,满足 $1\leq t\leq 10^5,1\leq n\leq 10^6,\sum n\leq 2\times 10^6,1\leq u,v\leq n$,保证 $T_1,T_2$ 是树。

子任务编号 $n$ $\sum n$ 特殊限制 分值
1 $\leq 10$ $\leq 100$ 4
2 $\leq 10^5$ $\leq 10^5$ $T_1=T_2$ 4
3 $T_2$ 是一条链 12
4 $\leq 100$ $\leq 1000$ 8
5 $\leq 1000$ $\leq 9969$ 20
6 $\leq 5\times 10^4$ $\leq 2\times 10^5$ 16
7 $\leq 2\times 10^5$ $\leq 6\times 10^5$ 20
8 $\leq 10^6$ $\leq 2\times 10^6$ 16

建议使用较快的读入方式。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.