#P15076. [ICPC 2024 Chengdu R] Disrupting Communications
[ICPC 2024 Chengdu R] Disrupting Communications
题目描述
The enemy has established communication outposts across several locations, which can be represented as nodes and edges in a network. This network forms a tree --- a type of graph that is connected and has no cycles. As a specialist in communications engineering, your task is to disrupt their communications.
Each communication occurs along a simple path between two nodes in the tree. You have the ability to select a subgraph of this tree and disrupt every node in that subgraph. If the communication path includes a disrupted node, the communication is successfully disrupted. The subgraph you select must consist of a subset of nodes and edges from the original tree, and it must be connected, meaning it is also a tree.
The communication network consists of nodes, labeled from to . Your mission involves answering separate queries. For each query, you are given two nodes, and , and you must determine how many different subgraphs you can select to disrupt the communication between the two nodes. Since the number may be very large, you should provide the answer modulo . It is possible that , which indicates an internal communication within a node, and you are also able to disrupt it by selecting a subgraph that contains the node.
输入格式
The first line contains a single integer (), indicating the number of test cases.
The first line of each test case contains two integers () and (), denoting the number of nodes and the number of queries.
The second line contains integers (), indicating that nodes and are connected by an edge.
Each of the next lines contains two integers (), representing the -th query.
It is guaranteed that the sum of and the sum of over all test cases do not exceed , respectively.
输出格式
For each test case, output lines, each containing the result modulo for one of the queries.
2
3 2
1 1
2 3
1 2
5 3
1 1 2 2
4 5
2 4
2 3
6
5
14
13
15
提示
In the first case of the example, connected subgraphs can be selected in total. For the first query, all of them can disrupt the communication. For the second query, of them can disrupt the communication; the exception is the subgraph consisting only of node .