Bring Them There
Time limit2sMemory limit128 MB
Find the minimum number of days to send K ships from S to T through an undirected graph where each edge carries at most one ship per day.
- Level
Hard8 of 10
- Topics
- Graph, BFS, Dynamic programming, Shortest path
- Solved
- No attempts yet
Problem
By the year 3141, humanity has spread across the entire galaxy. Travel between star systems relies on special hypertunnels. To use a hypertunnel you fly your spaceship to a launch point near the source star, activate the hyperjumper, pass through the tunnel, emerge near the destination star, and fly on to the planet you need. The whole trip takes exactly one day.
The system has one limitation: on any given day, each tunnel can carry at most one spaceship. In particular, two ships may never travel through the same tunnel on the same day, not even in opposite directions.
You work in the transportation department of a large corporation. Today you must deliver supercomputers from Earth (star system ) to the planet Eisiem (star system ). Each supercomputer is so large that it fills an entire spaceship, so one ship can carry only one supercomputer at a time. You have as many spaceships as you need, and a ship may wait at any star system for any number of days. You may use any tunnel whenever you need it, subject only to the one-ship-per-tunnel-per-day rule.
Find the minimum number of days required to deliver all supercomputers from to .
Input
The first line contains five integers , , , , : the number of star systems, the number of tunnels, the number of supercomputers to deliver, the source star system (Earth), and the destination star system (Eisiem), with , , , , and .
Each of the next lines contains two distinct integers describing one tunnel and the two star systems it connects. A tunnel can be traveled in either direction, but only one ship may use it per day. No tunnel connects a star system to itself, and any two star systems are connected by at most one tunnel.
It is guaranteed that at least one route exists from to .
Output
Print a single integer: the minimum number of days needed to deliver all supercomputers from star system to star system .