#P15654. [省选联考 2026] 工业系统
[省选联考 2026] 工业系统
Background
Recently, while doing archaeology in her own garden, Xiaofei found some industrial devices that looked very old. Out of curiosity, she suddenly decided to test the performance of these devices.
So she found some conveyor belts and, following the shape of a peach tree in the garden, connected these devices together to form an industrial system.
As for the specific testing method, you will naturally answer Xiaofei’s questions. Surely you will not refuse.
Problem Description
You are given an industrial system containing devices, numbered . These devices are connected by directed conveyor belts whose directions can be changed, forming an unrooted tree.
When using this system, you first need to choose a device () as the final device, and then set the direction of every conveyor belt to point toward that device. Formally, device is chosen as the root of the tree, and all conveyor belts are directed toward the root, forming an inward rooted tree. After the directions are fixed, all products will be transported along the conveyor directions.
Each device takes the products of all its descendants as input products, then produces a new product, and outputs it along the conveyor belt to all its ancestors. Formally, let the product of device () be . Let all devices in the subtree of except itself be . Then its product can be represented as the multiset . In particular, if device is a leaf device, i.e. has no descendants, then .
To compare product quality, define the order between products as follows. When device () is chosen as the final device, for products of devices (), sort all elements in and (i.e. all input products of devices ) from large to small, obtaining two sequences. The lexicographic order of these two sequences is defined as the order between and . Formally, let , , where and . Then:
- if and only if one of the following holds:
- There exists a positive integer such that , and for all we have .
- For all we have , and .
- if and only if and for all we have .
After defining the order, we define the rank of a product. Specifically, define () as: when device is chosen as the final device, the rank of device ’s product among all products. Formally,
To fully analyze the role of each device in this industrial system, you need to answer queries. Each query is:
- Given five parameters .
- Define$$X = \begin{cases} \{s\}, & o_x = 0, \\ \text{ch}(s,t), & o_x = 1, \end{cases} \quad Y = \begin{cases} \{t\}, & o_y = 0, \\ \text{ch}(s,t), & o_y = 1, \end{cases}$$
- where denotes the set of all devices on the simple path from device to device .
- Find how many pairs satisfy , , and .
Input Format
The first line contains a non-negative integer , the test point ID. means this test point is the sample.
The second line contains a positive integer , the number of devices in the industrial system.
The -th line () contains two positive integers , meaning the -th conveyor belt connects devices and .
The -th line contains a positive integer , the number of queries.
The -th line () contains five non-negative integers , the parameters of the -th query.
Output Format
Output lines. The -th line () contains a non-negative integer, the answer to the -th query.
0
3
1 2
2 3
6
1 2 0 0 2
1 3 0 0 2
2 3 0 0 2
2 1 0 0 2
3 1 0 0 2
3 2 0 0 2
1
0
1
1
0
1
Hint
Sample 1 Explanation.
- When device is the root:
- Device is a leaf device, so .
- The descendants of device are device , so .
- The descendants of device are devices , so .
- Therefore , i.e. , , .
- When device is the root:
- Devices are leaf devices, so .
- The descendants of device are devices , so .
- Therefore , i.e. , .
- When device is the root:
- Device is a leaf device, so .
- The descendants of device are device , so .
- The descendants of device are devices , so .
- Therefore , i.e. , , .
Sample 2.
See industry/industry2.in and industry/industry2.ans in the contestant directory.
Sample 2 Explanation.
- When device is the root, , , $a_{1,3} = \{\varnothing, \varnothing, \{\varnothing\}\}$, $a_{1,1} = \{\varnothing, \varnothing, \varnothing, \{\varnothing\}, \{\varnothing, \varnothing, \{\varnothing\}\}\}$, so $a_{1,1} > a_{1,3} > a_{1,4} > a_{1,2} = a_{1,5} = a_{1,6}$.
- When device is the root, $a_{2,2} > a_{2,4} > a_{2,3} > a_{2,1} > a_{2,5} = a_{2,6}$.
- When device is the root, $a_{3,3} > a_{3,1} = a_{3,4} > a_{3,2} = a_{3,5} = a_{3,6}$.
- When device is the root, $a_{4,4} > a_{4,3} > a_{4,1} > a_{4,2} = a_{4,5} = a_{4,6}$.
- When device is the root, $a_{5,5} > a_{5,1} > a_{5,3} > a_{5,4} > a_{5,2} = a_{5,6}$.
- When device is the root, $a_{6,6} > a_{6,3} > a_{6,1} = a_{6,4} > a_{6,2} = a_{6,5}$.
Sample 3.
See industry/industry3.in and industry/industry3.ans in the contestant directory.
Sample 4.
See industry/industry4.in and industry/industry4.ans in the contestant directory.
This sample satisfies .
Sample 5.
See industry/industry5.in and industry/industry5.ans in the contestant directory.
This sample satisfies and .
Sample 6.
See industry/industry6.in and industry/industry6.ans in the contestant directory.
This sample satisfies and .
Sample 7.
See industry/industry7.in and industry/industry7.ans in the contestant directory.
This sample satisfies .
Sample 8.
See industry/industry8.in and industry/industry8.ans in the contestant directory.
This sample satisfies the constraints of test point .
Sample 9.
See industry/industry9.in and industry/industry9.ans in the contestant directory.
This sample satisfies the constraints of test point .
Sample 10.
See industry/industry10.in and industry/industry10.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 11.
See industry/industry11.in and industry/industry11.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 12.
See industry/industry12.in and industry/industry12.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 13.
See industry/industry13.in and industry/industry13.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 14.
See industry/industry14.in and industry/industry14.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 15.
See industry/industry15.in and industry/industry15.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 16.
See industry/industry16.in and industry/industry16.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 17.
See industry/industry17.in and industry/industry17.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 18.
See industry/industry18.in and industry/industry18.ans in the contestant directory.
This sample satisfies the constraints of test points .
Sample 19.
See industry/industry19.in and industry/industry19.ans in the contestant directory.
This sample satisfies the constraints of test point .
Constraints
For all testdata:
- .
- For all , , and form a tree.
- .
- , .
::cute-table{tuack}
| Test point ID | Special property | ||||
|---|---|---|---|---|---|
| A | |||||
| ^ | ^ | B | |||
| ^ | |||||
| ^ | ^ | ||||
| ^ | |||||
| ^ | None | ||||
| ^ | |||||
| ^ | B | ||||
| ^ | None | ||||
| ^ | |||||
| ^ | |||||
Special property A: There exists such that for all , we have or .
Special property B: The unrooted tree formed by all devices is generated uniformly at random among all labeled unrooted trees on nodes.
Translated by ChatGPT 5