QOJ.ac

QOJ

حد الوقت: 4 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#5023. 【Template】Heavy-Light Decomposition

الإحصائيات

Please do not abuse the judging resources.

Given a tree $T$ with $n$ nodes and $m$ distinct paths $I_i=(u_i,v_i)$ ($u_i \ne v_i$) on the tree. Specifically, $I_i$ denotes the set of all nodes on the simple path between $u_i$ and $v_i$ in the tree.

Consider a path $I=(u,v)$ on $T$, and 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 $I$ on $T$, calculate the sum of $f(I)$, and output the answer modulo $998\,244\,353$. That is, you need to calculate $\left(\sum\limits_{u = 1} ^ n\sum\limits_{v = u} ^ n f((u, v))\right) \bmod 998244353$.

Input

The first line contains an integer $S$, representing the subtask ID. The subtask ID for the sample is $-1$.

The second line contains two integers $n$ and $m$, representing the size of the tree and the number of paths, respectively.

The next $n-1$ lines each contain two integers $x_i, y_i$, representing an edge in $T$.

The next $m$ lines each contain two integers $u_i, v_i$, representing the $i$-th path $I_i$.

It is guaranteed that all given paths are distinct.

Output

Output a single integer representing the answer.

Examples

Input 1

-1
3 3
1 2
2 3
1 2
2 3
1 3

Output 1

32

Input 2

-1
4 6
1 2
1 3
1 4
1 2
1 3
1 4
2 3
2 4
3 4

Output 2

120

Input 3

-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

Output 3

330

Constraints

This problem uses bundled testing, with 25 subtasks numbered $0 \sim 24$. Note that the subtask ID used for evaluation is the actual subtask ID $+1$.

The subtask ID modulo 5 divides the subtasks by data size:

  • If the subtask ID modulo 5 is 0, then $n, m \leq 100$, denoted as A1.
  • If the subtask ID modulo 5 is 1, then $n, m \leq 500$, denoted as B1. Depends on A1.
  • If the subtask ID modulo 5 is 2, then $n, m \leq 1557$, denoted as C1. Depends on B1.
  • If the subtask ID modulo 5 is 3, then $n, m \leq 85500$, denoted as D1. Depends on C1.
  • If the subtask ID modulo 5 is 4, then $n, m \leq 2 \times 10^5$, denoted as E1. Depends on D1.

The quotient of the subtask ID divided by 5 divides the subtasks by special constraints:

  • If the quotient of the subtask ID divided by 5 is 0, then $T$ is a line, denoted as A2.
  • If the quotient of the subtask ID divided by 5 is 1, then $T$ is a star graph, denoted as B2.
  • If the quotient of the subtask ID divided by 5 is 2, all path endpoints are distinct, denoted as C2.
  • If the quotient of the subtask ID divided by 5 is 3, all paths share a common endpoint, denoted as D2.
  • If the quotient of the subtask ID divided by 5 is 4, there are no special constraints, denoted as E2. Depends on A2, B2, C2, D2.

For $100 \%$ of the data, $2 \leq n \leq 2 \times 10^5$, $1 \leq m \leq \min \left(\frac{n(n-1)}{2}, 2 \times 10^5\right)$, $1 \leq u_i, v_i, x_i, y_i \leq n$, all $(x_i, y_i)$ form a tree, all $I_i=(u_i, v_i)$ are distinct, and $u_i \neq v_i$. The scores for each subtask are shown in the table below.

Score A1 B1 C1 D1 E1 Total
A2 1 2 3 7 7 20
B2 1 2 3 4 4 14
C2 1 2 5 7 7 22
D2 1 3 5 4 5 18
E2 2 3 3 9 9 26
Total 6 12 19 31 32 100

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.