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 cotes). 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: | All |
hide comments
2021-06-19 19:12:07
Can s and d be equal? |
|
2020-05-07 07:21:37
Thanks for the problem ! Learned something new from this :) |
|
2018-08-11 14:25:41
I tried all possible optimization in dfs but still getting tle ... someone pls help @ryuuk please help |
|
2018-06-28 16:48:11 Muhammad Faishol Amirul Mukminin
Is it guarantee that "s != d" and no two paths have same "s d"? |
|
2018-06-22 16:34:11
To all who get WA, i think that you can run a stress code to get some test cases where your code fails. |
|
2018-06-21 10:06:36
is there a case where there is no route from departure city to destination city? RE: NO It is guaranteed that atleast one path exists between s and d. Last edit: 2018-06-22 17:41:35 |
|
2018-06-16 23:26:02
AC 0.0sec, very nice problem :D |
|
2018-06-16 19:05:08
The time limit is not sufficient Its showing TLE for all approaches.I think recheck time constraints once RE: time limit is good but you need to try other approaches Last edit: 2018-06-16 22:03:21 |