#P8821. [集训队互测 2022] 树链剖分
[集训队互测 2022] 树链剖分
Background
Please note: This problem is not a heavy-light decomposition template problem.
Problem Description
You are given a tree with nodes and distinct paths on the tree . Specifically, represents the set of all nodes on the simple path between and on the tree.
Consider a path on , . Define $f(I) = \sum\limits_{i = 1} ^ m\sum\limits_{j = 1} ^ m [I_i\cup I = I_j\cup I]$.
For all distinct paths on , find the sum of , and take the answer modulo . That is, you need to compute $\left(\sum\limits_{u = 1} ^ n\sum\limits_{v = u} ^ n f((u, v))\right) \bmod 998244353$.
Input Format
The first line contains an integer , indicating the subtask ID. In the sample, the subtask ID is .
The second line contains two integers , representing the size of the tree and the number of paths.
The next lines each contain two integers , representing an edge of .
The next lines each contain two integers , representing the -th path .
It is guaranteed that all given paths are pairwise distinct.
Output Format
Output one line with one integer, the answer.
-1
3 3
1 2
2 3
1 2
2 3
1 3
32
-1
4 6
1 2
1 3
1 4
1 2
1 3
1 4
2 3
2 4
3 4
120
-1
7 7
1 2
1 3
2 4
4 5
5 6
5 7
5 7
3 1
4 7
7 1
2 6
3 6
3 5
330
Hint
This problem uses bundled testdata, with a total of subtasks, numbered . Note that the evaluated subtask ID equals the actual subtask ID .
The remainder of the subtask ID modulo classifies subtasks by data size.
- If the subtask ID modulo is , then , denoted as A1.
- If the subtask ID modulo is , then , denoted as B1. Depends on A1.
- If the subtask ID modulo is , then , denoted as C1. Depends on B1.
- If the subtask ID modulo is , then , denoted as D1. Depends on C1.
- If the subtask ID modulo is , then , denoted as E1. Depends on D1.
The quotient of the subtask ID divided by classifies subtasks by special constraints.
- If the quotient is , then is a chain, denoted as A2.
- If the quotient is , then is a star, denoted as B2.
- If the quotient is , then all path endpoints are pairwise distinct, denoted as C2.
- If the quotient is , then all paths share one common endpoint, denoted as D2.
- If the quotient is , then there are no special constraints, denoted as E2. Depends on A2, B2, C2, D2.
Constraints
For of the data, , $1\leq m\leq \min(\frac {n(n - 1)} 2, 2\times 10 ^ 5)$, , and all form a tree, all are pairwise distinct, and .
The scores of each subtask are shown in the following table.
| Score | A1 | B1 | C1 | D1 | E1 | Total |
|---|---|---|---|---|---|---|
| A2 | ||||||
| B2 | ||||||
| C2 | ||||||
| D2 | ||||||
| E2 | ||||||
| Total | ||||||
Note: Luogu evaluation has no subtask dependencies.
Source: 2022 CTT Mutual Test Round 4.
Problem setter: Alex_Wei.
Translated by ChatGPT 5