The Flight Plan
Practice
4.2 (74 votes)
Algorithms
Breadth first search
Easy
Graphs
Problem
89% Success 13632 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given flights route map of a country consisting of N cities and M undirected flight routes. Each city has an airport and each airport can work as layover. The airport will be in two states, Loading and Running. In loading state, luggage is loaded into the planes. In the running state, planes will leave the airport for the next city. All the airports will switch their states from Loading to Running and vice versa after every T minutes. You can cross a city if its airport state is running. Initially, all the airports are in running state. At an airport, if its state is loading, you have to wait for it to switch its state to running. The time taken to travel through any flight route is C minutes. Find the lexicographically smallest path which will take the minimum amount of time (in minutes) required to move from city X to city Y.

It is guaranteed that the given flight route map will be connected. Graph won't contain multiple edges and self loops. A self loop is an edge that connects a vertex to itself.

Input Format:
The first line contains 4 space separated integers, N, M, T and C. Next M lines contains two space separated integers each, U and V denoting that there is a bidirectional road between city U and city V. Next line contains two space separated integers, X and Y.

Output Format:
In the first line print an integer K, denoting the number of city you need to go through to reach city Y from the city X. In next line, print K space separated integers denoting the path which will take the minimum amount of time (in minutes) required by to move from city X to city Y. There can be multiple paths. Print the lexicographically smallest one.

Constraints:
\(1 \le N \le 10^3\)
\(N-1 \le M \le \frac {N*(N-1)} 2\)
\(1 \le C \le 10^3\)
\(1 \le T \le 10^3\)
\(1 \le U, V, X, Y \le N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
46 votes
Tags:
AlgorithmsApprovedBreadth First SearchDepth First SearchEasyGraphsOpen
Points:20
15 votes
Tags:
AlgorithmsBreadth First SearchGraphsLogic-Based
Points:20
184 votes
Tags:
Breadth First SearchEasyGraphsOpen