National Olympiad in Informatics, China, 2003
While Alex was solving "The Lucky Mouse" from the NOI2003 practice contest, he felt that it was too easy, so he made some changes:
- Change the limit of
in the original problem from
to
.
- Change the time required to cross a street to
minutes (where
is the street number).
- A condition is introduced: the distance between Tyke's house
and Jerry's house
is less than or equal to the distance between Spike's house
and Jerry's house
. Even still, Alex was able to solve the problem really quickly. So, he decided to create some input data to test his program. He has just created some layouts satisfying these conditions, but to increase the difficulty of the data, he wishes for you to help him determine a set of values for
,
, and
, such that the time it takes for Jerry to receive his presents is maximized.
Revised Problem (Note: You do not have to solve this)
Lucky Jerry Mouse's birthday is coming up, and the bulldogs Spike and
Tyke would each like to give him a birthday present. To receive the
presents, Jerry plans to depart from his house , first arriving at
Tyke's house
(because the distance from Tyke's house
to Jerry's
house
is less than or equal to the distance between Spike's house
to
Jerry's house
), and finally arriving at Spike's house
.
Toontown consists of
houses and
two-way streets connecting the houses. Traveling along the
-th street
requires a time of
minutes.
It is guaranteed that there a path will exist between any two houses.
Jerry's house is at location , Tyke's house is at location
, and
spike's house is at location
. Please calculate the shortest possible
time Jerry needs to spend before receiving his presents.
Task Description
Definition: Let represent the minimum time it takes to get from
house
to house
in Toontown.
Given the layout of Toontown, find values for ,
, and
such
that:
, and
is maximized.
Determine the value of .
Input Specification
The first line of input will contain two integers
and
, representing the total number of houses
and streets. Lines 2 through line
will each provide information on
one street. Line
will contain integers
,
, and
,
indicating that the
-th street connects houses
and
and takes
minutes to traverse.
Output Specification
The output should contain a single integer , the maximum possible
value for
.
Sample Input
4 3
1 2 1
2 3 1
3 4 1
Sample Output
4
Problem translated to English by .
Comments