#P5416. [CTSC2016] 时空旅行
[CTSC2016] 时空旅行
Description
In 2045, human technology advanced rapidly, and people have found a way to travel through time and space. Little R obtained a time-space travel device and wants to use it to investigate the development of humans in different time-spaces.
According to the parallel time-space theory, there are many independent time-spaces in the universe. Each time-space will further split into several different time-spaces at the next time point. The universe is a three-dimensional space, and humans use a 3D Cartesian coordinate system to describe a position in space, with coordinates .
Assume that in the initial time-space (numbered ), humans live on Earth (Earth’s coordinates are ), and all other time-spaces are developed from an existing time-space. After one time step, a time-space will develop into another time-space (the original time-space does not change). Events that affect Little R are of two types:
- Humans colonize a new planet, and the planet’s state becomes “colonized”.
- Humans abandon a colonized planet, and the planet’s state becomes “not colonized”.
Each time Little R performs time-space travel, he first chooses a time-space. In this time-space, humans have already colonized some planets. As long as Little R reaches any colonized planet in that time-space, he can investigate the development of humans.
However, Little R’s device has some problems: the button for adjusting the coordinate is broken, so the coordinate of the destination point is fixed (the fixed value may differ for each trip). At the same time, he can still freely adjust the and coordinates of the destination.
This greatly increases Little R’s cost: time-space travel itself is free, but traveling in space costs money; also, investigating on different planets may incur different fees.
Suppose Little R sets the endpoint of the time-space travel to , and the planet he investigates is . If the Euclidean distance between and is , then the cost of space travel is . If the investigation fee on planet is , then the total cost of this investigation is .
Now you are given the time-space Little R arrives at for each trip and the fixed coordinate value on the device. Please compute the minimum total cost for Little R to complete the investigation for each trip.
Input Format
The first line contains three non-negative integers . is the number of parallel time-spaces, numbered from to , and the initial time-space is numbered . is the number of time-space trips Little R makes. is the investigation fee on Earth. It is guaranteed that , and .
The next lines describe parallel time-spaces to in order. For time-space , the -th line is one of the following two cases:
- : time-space develops from time-space , and humans colonize a planet with number . The planet’s coordinates are , and the investigation fee on this planet is . The testdata guarantees that the given planet numbers are all distinct, and . Also, , and .
- : time-space develops from time-space , and humans abandon the planet with number . The testdata guarantees that this planet is colonized in time-space . Also, , meaning Earth will never be abandoned.
In both cases above, all parameters are positive integers, and adjacent integers are separated by one space. It is also guaranteed that . No other cases will appear.
The next lines each describe one time-space trip by Little R. Each line contains two positive integers and , meaning that Little R travels to parallel time-space , and the device fixes the coordinate to . It is guaranteed that and .
Output Format
Output lines. The -th line should be the minimum total cost to complete the investigation for the -th trip.
4 4 2
0 0 1 8 2 3 7
0 1 2 10 1 6 2
1 1 1
1 4
2 8
2 6
3 8
18
6
11
66
Hint
For the first of the testdata, .
There is another of the testdata with . Among them, for of the testdata, humans never abandon planets, and for another of the testdata, the value is the same for every trip.
For the remaining testdata, . Among them, for of the testdata, the value is the same for every trip, and for of the testdata, time-space develops from time-space . In this , there is of the testdata where humans never abandon planets.
Because the compressed file is too large to upload, for each subtask there is one and only one test point, corresponding to its score.
Translated by ChatGPT 5
京公网安备 11011102002149号