#P10439. [JOIST 2024] 逃生路线 2 / Escape Route 2
[JOIST 2024] 逃生路线 2 / Escape Route 2
Problem Description
The IOI Kingdom consists of cities arranged from west to east. The cities are numbered from to in order from west to east.
In the IOI Kingdom, they use Byou as the unit of time. One day in the IOI Kingdom is divided into time units. The time Byous () after the start of some day is called time . Therefore, when Byou passes starting from time of some day, it becomes time of the next day.
The JOI Organization is one of the secret cults in the IOI Kingdom. Since it is a secret cult, its members must bypass the kingdom’s checkpoints. Therefore, JOI Organization members can only travel between cities using flights operated by JOY Airlines.
JOY Airlines offers flights in city (). Flight () departs from city every day at time and arrives at city at time on the same day. Here, holds.
These flights provide convenient connections: you may depart immediately after arriving, or stay overnight at the airline’s airport.
The JOI Organization has members, numbered from to . Member () has their operation base in city and their living base in city . Therefore, they want to know the shortest time needed to travel from city to city , by choosing a departure time from city and taking suitable flights.
Given the flights operated by JOY Airlines and the information about the JOI Organization members, write a program to find, for each member , the shortest time to travel from city to city .
Input Format
Read the following data from standard input.
- ...
- ...
- ...
- ...
- ...
Output Format
Output lines to standard output. On line (), output the shortest time required for member to travel from city to city .
4 10000
1
100 300
2
200 400
300 600
1
500 600
3
1 3
2 4
1 4
500
400
10500
6 10000
1
100 300
1
400 700
1
500 600
1
300 900
1
200 800
1
1 6
30700
Hint
Sample Explanation 1
For demonstration, let us call the first day on which member departs from city Day . Member can travel from city to city in Byou as follows.
- Depart from city at time on Day , and arrive at city at time on Day .
- Depart from city at time on Day , and arrive at city at time on Day .
Since there is no faster way to travel, output on line .
Member can travel from city to city in Byou as follows.
- Depart from city at time on Day , and arrive at city at time on Day .
- Depart from city at time on Day , and arrive at city at time on Day .
Since there is no faster way to travel, output on line .
Member can travel from city to city in Byou as follows.
- Depart from city at time on Day , and arrive at city at time on Day .
- Depart from city at time on Day , and arrive at city at time on Day .
- Depart from city at time on Day , and arrive at city at time on Day .
Since there is no faster way to travel, output on line .
This sample input satisfies the constraints for Subtasks .
Sample Explanation 2
This sample input satisfies the constraints for all subtasks.
Constraints
- ()
- ()
- ()
- All given values are integers.
Subtasks
- (6 points) , ().
- (8 points) , ().
- (17 points) ().
- (23 points) ().
- (36 points) , , .
- (10 points) No additional constraints.
Translated by ChatGPT 5