#P9166. [省选联考 2023] 火车站
[省选联考 2023] 火车站
Problem Description
There are train stations in a straight line, numbered from to . There are railway tracks in total, and each track covers an interval of stations .
At a station covered by multiple tracks, when a train passes through, it may switch tracks there. However, the train cannot turn around, and can only run in one direction (that is, it can only keep moving toward station or keep moving toward station ).
Person A starts from station , meaning they board any train that passes through (this train may also depart from station ). This train may run on any track that covers station , and its direction may be toward or toward . After boarding, Person A falls asleep, and only wakes up when the train stops at the terminal station of some track. Ask which stations Person A may finally reach.
Note: The train must travel through at least one station. Also, after switching tracks, the train will not stop immediately; instead, it will continue moving along the current track.
Input Format
The first line contains three positive integers , representing the number of stations, the number of tracks, and Person A’s starting station.
The next lines each contain two positive integers , representing the operating interval of a track.
Output Format
Output one line containing several positive integers separated by single spaces, representing the stations that Person A may finally reach. Output them in increasing order of station number.
7 5 4
3 4
4 6
1 3
5 7
4 6
1 3 6 7
Hint
Sample 1 Explanation
Starting from station , if the train takes the first track, it can reach the terminal station , or it can then continue along the third track to reach the terminal station .
Starting from station , if the train takes the second track, it can reach the terminal station , or it can switch to the fourth track at station and reach the terminal station .
So the final output in order is .
Constraints
For all testdata, it is guaranteed that , , .
| Test Point | Special Property | |
|---|---|---|
| 1 | None | |
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | A | |
| 7 | ||
| 8 | None | |
| 9 | ||
| 10 |
Special Property A: It is guaranteed that .
Translated by ChatGPT 5