Robots
Time limit1sMemory limit1024 MB
Find the fewest nights for LRATB to reach village F from S without ever sharing a village with AtlasTiger, whose route after day one is unknown.
Statement
Cimrman Dynamics is testing its new model, the Long Range Autonomous Trekking Bot (LRATB). LRATB has to travel from village to village in the region. For environmental and safety reasons, LRATB moves only at night, and each night it may relocate only to a village adjacent to its current one along a cycling path.
Overseas Dynamics is testing a similar product in the same area. Its humanoid robot AtlasTiger also moves only at night, and each night it relocates from its village to an adjacent one.
If both robots stay in the same village for the whole day (from dawn to dusk), the signal interference may damage the navigation systems. LRATB must therefore follow a route where the two robots are never in the same village during the same day. The team knows only where AtlasTiger is on the first day, , and knows nothing about its later moves. LRATB may stay in a village overnight without leaving it. If the two robots cross each other on the same path at night in opposite directions, there is no risk.
Both robots start at dawn of the same day in their starting villages. Find the shortest time for LRATB to reach such that no interference can occur, whatever AtlasTiger does.
Input
The first line contains five integers , , , , . Here is the number of villages, is the number of paths, is the destination village, is the starting village of AtlasTiger, and is the starting village of LRATB. Each of the next lines contains two village labels that are connected by a path.
Constraints: , , . Villages are labelled . No path connects a village to itself, and no two paths connect the same pair of villages.
Output
Print the minimal number of nights LRATB needs to reach village with no interference guaranteed. If no such route exists, print death.