Always Catch your Mon, Inc., (also know as ACM), wants to
create a new product, called Pokémon Go Go. Users can purchase
this application to help them play Pokémon go. The software
accesses the poké stop locations near the current location as
well as a list of Pokémon that can be found at each stop. The
application then computes the shortest route one can follow to
catch all the unique Pokémon, and return to the starting point.
The program assumes that the user is in a city where travel
is restricted to moving only in the north–south and east–west
directions. The program also assumes that all poké stops are on
the intersection of two roads.
For example, consider a case where the application finds
five nearby poké stops. Each stop’s location is indicated by
two integers, (,), where is the number of blocks north of
your starting position and is the number of blocks west of
your starting position. Consider if the locations of the five
poké stops are ,
, , and while the names of the Pokémon
found at these stops are Evevee, Flareon, Flareon, Jolteon, and
Umbreon, respectively. It is clear that one does not have to
visit both the second and third stops, since the same Pokémon
can be caught at either of them. The best route is to visit the
first, fifth, fourth, and third stops (in that order) for a
total distance of
blocks, since:
-
The distance from to is .
-
The distance from to
is .
-
The distance from to is .
-
The distance from to is .
-
The distance from to is .
Input
The input holds a single test case. The test case begins
with a single integer ,
, which
indicates the number of poké stops to consider. Each of the
next lines specifies
the location of a poké stop and the name of a Pokémon that can
be found there. The location is specified by two integers
and separated by a single space,
.
The integers and
indicate that the stop
is blocks north and
blocks east of the
starting point. The location is followed by a single space and
followed by the string
indicating the name of the Pokémon that can be caught there.
Names have between and
letters (using only
a–z and A–Z). The number of unique Pokémon is always less than
or equal to . Multiple
pokémon can reside at the same location (but are then listed as
separate poké stops).
Output
Give the shortest distance, in blocks, required to catch all
the unique Pokémon.
Sample Input 1 |
Sample Output 1 |
5
5 9 Eevee
20 20 Flareon
1 1 Flareon
1 8 Jolteon
2 8 Umbreon
|
28
|