#P8820. [CSP-S 2022] 数据传输
[CSP-S 2022] 数据传输
Description
Xiao C is designing a routing system for a computer network.
The test network has hosts, numbered . These hosts are connected by network cables; the -th cable connects hosts and . It is guaranteed that any two hosts are connected directly or indirectly through a finite number of cables. Due to transmission power limits, host can directly send information to host if and only if the two hosts are connected directly or indirectly by a path that uses at most cables.
In a computer network, data transmission often requires several forwards. Suppose Xiao C needs to send data from host to host (). He will choose several hosts for transmission , and forward as follows: for all , host directly sends information to .
Each host needs some time to process information. The -th host needs units of time. Data transmission in the network is very fast, so the transmission time can be ignored. Therefore, the total time cost of the above process is .
There are data sending requests in total. In the -th request, data is sent from host to host . Xiao C wants to know, for each request, the minimum number of time units needed to complete the transmission.
Input Format
The first line contains three positive integers , denoting the number of hosts, the number of requests, and the transmission parameter, respectively. It is guaranteed that , , .
The second line contains positive integers; the -th integer is , and it is guaranteed that .
The next lines; the -th line contains two positive integers , indicating a network cable connecting hosts and . It is guaranteed that .
The next lines; the -th line contains two positive integers , indicating a request to send data from host to host . It is guaranteed that and .
Output Format
Output lines. Each line contains one positive integer, the minimum number of time units needed to complete the -th request.
7 3 3
1 2 3 4 5 6 7
1 2
1 3
2 4
2 5
3 6
3 7
4 7
5 6
1 2
12
12
3
Hint
【Sample Explanation #1】
For the first request, since hosts and require at least cables to connect, data cannot be transmitted directly between the two hosts, so at least one forward is required. Let it be forwarded once at host . It is easy to see that both host and host are within two cables from host , and host has a processing time of only , the minimum among all hosts. Therefore, the minimum transmission time is .
For the third request, since hosts and are connected by only cable, direct transmission is optimal, and the minimum transmission time is .
【Sample #2】
See the attachments transmit/transmit2.in and transmit/transmit2.ans.
This sample satisfies the limits of test point .
【Sample #3】
See the attachments transmit/transmit3.in and transmit/transmit3.ans.
This sample satisfies the limits of test point .
【Sample #4】
See the attachments transmit/transmit4.in and transmit/transmit4.ans.
This sample satisfies the limits of test point .
Constraints
For all testdata, it is guaranteed that , , , , , and .
| Test point | Special property | |||
|---|---|---|---|---|
| Yes | ||||
| No | ||||
| Yes | ||||
| No | ||||
| Yes | ||||
| No | ||||
Special property: it is guaranteed that , and is chosen uniformly at random from .
Translated by ChatGPT 5
京公网安备 11011102002149号