Teleport 3
Time limit2sMemory limit512 MB
Find the shortest travel time on a grid where you can walk one unit per second or take any of three two-way teleports costing 10 seconds each.
- Level
Medium4 of 10
- Topics
- Graph, Shortest path, Implementation
- Solved
- No attempts yet
Problem
Subin lives on an infinite grid. Each point of the grid is a pair of integers .
Subin starts at and wants to reach home at .
There are two ways to move. The first is a jump. From Subin moves to one of , , , , and one jump takes 1 second.
The second is a teleport. Three teleports are fixed in advance, and each one is given by the four coordinates , . It carries Subin from to or from to , and one teleport takes 10 seconds. The same teleport may be used any number of times.
Given Subin's position and the position of the house, write a program that computes the shortest time to get home.
Input
The first line contains and , and the second line contains and . ()
Each of the next three lines contains the information of one teleport, , , , . ()
All eight coordinates given in the input are distinct.
Output
Print the shortest time in seconds for Subin to get home.