Intercept
Time limit1sMemory limit256 MB
Find every station that lies on all shortest routes from s to t in a directed weighted graph.
- Level
Medium7 of 10
- Topics
- Shortest path, Graph, Topological sort
- Solved
- No attempts yet
Problem
Fatima rides the subway home from KTH every day. Today Robert baked cookies and wants to surprise her by bringing them to a station somewhere along the way. Fatima does not always take the same route home, because she likes to look at the artwork inside the different stations of Stockholm. She always keeps her travel time as short as possible, so she only uses shortest routes. Tell Robert which stations he can go to and still be certain to meet Fatima.
In other words, report every station that all shortest paths from to pass through.
Input
The first line contains two integers and , the number of subway stations and the number of subway links. ()
Each of the next lines contains three integers , , (, ), meaning that there is a one way link from station to station that takes seconds to complete. Different subway lines may serve the same route, so the same pair can appear more than once.
The last line contains two integers and (), the number of the station closest to KTH and the number of the station closest to home. Station is reachable from station .
Output
Print on one line every station number such that all shortest paths from to pass through , in increasing order. Separate the numbers with single spaces.