Submit | All submissions | Best solutions | Back to list |
STOPCITY - Stopping-off Cities |
You work for a tour operator which plans to commercialize different visiting tours in a country. A tour is a sequence of cities that are visited during the trip. A city cannot be visited more than once in one tour. Each city is represented as a node in a non-oriented graph where edges are possible connections. Given a departure city A and a destination city B, we call stopping-off-city a city that is part of at least one possible tour between A and B. Your mission is to select all possible stopping-off-cities between A and B. In the example of the figure bellow, we have a graph of 20 cities. If we consider the departure as node 10 and the arrival as node 16 the stopping-off-cities are {8, 9, 10, 11, 12, 13, 15, 16}.
Input
First line of input consists of an integer V denoting the number of nodes or cities (V ≤ 10000). Then, each line contains an edge definition as two space separated integers (link between two cities). Edges description ends with the line "-1 -1" (without quotes). The last line contains two space separated integers "s d" where s is the departure city and d the destination city.
Output
A space separated sorted list of stopping-off-cities including s and d. It is guaranteed that at least one path exists between s and d.
Example
Input: 20 0 1 1 2 2 3 3 4 4 5 5 6 6 7 1 8 8 11 8 9 9 10 11 12 9 12 12 13 12 15 12 14 14 19 14 18 14 17 17 18 18 19 13 15 15 16 -1 -1 10 16 Output: 8 9 10 11 12 13 15 16
Added by: | adminensi |
Date: | 2018-06-04 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | JAVA |