第 233 场 AtCoder Regular Contest++
C
等度数删除
Equal Degree Deletion
AtCoder
⌀ 2797
原题
← BD →

等度数删除AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given a tree $G$ with $N$ vertices and $N-1$ edges. The vertices are numbered $1$ to $N$, and the edges are numbered $1$ to $N-1$. Edge $i$ connects vertices $u_i$ and $v_i$.

给定一棵有 $N$ 个顶点和 $N-1$ 条边的树 $G$。 顶点编号为 $1$ 到 $N$,边编号为 $1$ 到 $N-1$。边 $i$ 连接顶点 $u_i$ 和 $v_i$。AI (CI翻译)

A tree $H$ is called special if it is possible to delete all edges of $H$ by performing the following operation zero or more times.

如果可以通过零次或多次执行以下操作删除树 $H$ 的所有边,则称树 $H$ 是特殊的。AI (CI翻译)

  • Choose an edge connecting two vertices whose current degrees are equal, and delete it.
  • 选择一条连接当前度数相同的两个顶点的边,并将其删除。
AI (CI翻译)

Find the number of special subtrees of $G$, modulo $998244353$.

求 $G$ 的特殊子树数量,答案对 $998244353$ 取模。AI (CI翻译)

Solve $T$ test cases for each input.

对于每组输入,求解 $T$ 组测试用例。AI (CI翻译)

What is a subtree? A subtree of a tree $G$ is a connected subgraph of $G$.

什么是子树?树 $G$ 的子树是 $G$ 的一个连通子图。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq T \leq 10^5$
  • $2 \leq N \leq 3 \times 10^5$
  • The sum of $N$ over all test cases is at most $3 \times 10^5$.
  • $1 \leq u_i \lt v_i \leq N$
  • The given graph $G$ is a tree.
  • All input values are integers.
  • $1 \leq T \leq 10^5$
  • $2 \leq N \leq 3 \times 10^5$
  • 所有测试用例的 $N$ 之和不超过 $3 \times 10^5$。
  • $1 \leq u_i \lt v_i \leq N$
  • 给定的图 $G$ 是一棵树。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入通过标准输入给出,格式如下:AI (CI翻译)

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
AI (CI翻译)

Each test case $\mathrm{case}_t$ is given in the following format:

每组测试用例 $\mathrm{case}_t$ 的格式如下:AI (CI翻译)

N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}

N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Print $T$ lines in total. The $t$-th line should contain the answer for the $t$-th test case.

总共输出 $T$ 行。第 $t$ 行应包含第 $t$ 组测试用例的答案。AI (CI翻译)

样例

Input #1
3
6
1 3
2 3
3 4
4 5
4 6
10
2 6
4 5
3 9
6 8
3 5
6 10
3 7
1 10
2 5
2
1 2
Output #1
15
35
3
In the first test case, the $6$ subtrees consisting of one vertex and the $5$ subtrees consisting of two vertices and one edge are special. Also, the subtree of $G$ consisting of vertices $1,3,4,6$ and edges $1,3,5$ is special, since the operation can be performed to delete edges $3,5,1$ in this order.
题目信息
题号
arc233_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。