QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#14574. Everlasting Friends?

统计

等到一切有关这【】OI 的事情结束,所有的利益与竞争化为乌有,我们还会是朋友……吗?

题目描述

小 $\sigma$ 有一张包含 $n$ 个人,$n-1$ 条朋友关系的关系网。保证在这个关系网中所有人连通,也就是说,将 $n$ 个人视为点,$n-1$ 条朋友关系视为边后该关系网为一棵树。

关系网是会变化的,毕竟没有永远的朋友。

小 $\sigma$ 常常追忆过去,他想起过去的关系网是现在关系网按 $1,2,3,\dots,n$ 顺序加入点后的重构树。

小 $\sigma$ 常常幻想未来,他发现未来的关系网是现在关系网按 $n,n-1,n-2,\dots,1$ 顺序加入点后的重构树。

小 $\sigma$ 定义,对于某两张关系网而言,如果 $\{1,2,3,\dots,n\}$ 的一个非空集合 $S$ 在两张关系网上的导出子图均为一个连通块,则 $S$ 为这两张关系网的不变朋友子集

小 $\sigma$ 想知道,过去的关系网与现在的关系网有多少不变朋友子集以及过去的关系网与未来的关系网有多少不变朋友子集。由于答案可能较大,你只需要输出答案对 $998244353$ 取模后的值即可。


形式化题意

给定一棵 $n$ 个点的树 $T$,定义 $T_{\max}$ 为按 $1,2,3,\dots,n$ 顺序加入点后的重构树,$T_{\min}$ 为按 $n,n-1,n-2,\dots,1$ 顺序加入点后的重构树,$f(T_1,T_2)$ 为使得 $S$ 在 $T_1,T_2$ 上的导出子图均为连通块的 $\{1,2,3,\dots,n\}$ 的非空子集 $S$ 个数。求 $f(T_{\max},T)$ 与 $f(T_{\max},T_{\min})$ 对 $998244353$ 取模后的值。


按顺序 $ord_1,ord_2,ord_3,\dots,ord_n$ 加入点构建重构树的具体流程为:

  1. 维护点集 $S$,按 $i=1,2,3,\dots,n$ 依次遍历每个 $p=ord_i$。
  2. 对于所有在原树上与 $p$ 相邻且在 $S$ 中的点 $q$,将 $S$ 点集的导出子图中 $q$ 所在连通块最晚加入 $S$ 的点在重构树上与 $p$ 连边。
  3. 将 $p$ 加入点集 $S$。

输入格式

第一行两个正整数 $tp,n$,分别表示询问类型与点数。$tp=1$ 时你需要输出过去的关系网与现在的关系网有多少不变朋友子集,$tp=2$ 时你需要输出过去的关系网与未来的关系网有多少不变朋友子集

接下来 $n-1$ 行,每行两个正整数 $u_i,v_i$,表示一条朋友关系。保证在这个关系网中所有人连通。

输出格式

一行,输出一个非负整数,表示答案对 $998244353$ 取模后的值。

样例

样例 1 输入

1 6
3 1
1 6
6 4
4 2
4 5

样例 1 输出

15

样例 2 输入

2 6
3 1
1 6
6 4
4 2
4 5

样例 2 输出

13

数据范围

子任务编号 $n \leq$ $tp=$ 特殊限制 分值
1 $10$ $1$ 5
2 $2000$ 15
3 $2\times10^5$ 树退化为一条链 5
4 树退化为菊花图 5
5 10
6 $10$ $2$ 5
7 $100$ 10
8 $500$ 10
9 $5000$ 10
10 $2\times10^5$ 树退化为一条链 5
11 树退化为菊花图 5
12 15

对于所有数据:$1\leq tp\leq 2$,$1\leq n\leq2\times 10^5$,保证关系网中所有人连通。

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.