z-streets
Mr. Little Z and Mister S want to travel from town Izelgard to Deronjilous city. In their journey, they will be passing through some streets. Each street has a length and an average height of the trees on it. Any two of the M streets could be connected by some of N endpoints (intersections). The town Izelgard will be represented as an endpoint with the index 1 and Deronjilous city will be represented as an endpoint with the index N.
Mr. Little Z likes to travel along the shortest path and Mister S likes to travel along the streets that have very tall trees.
We will say that some street along the path is the highest street along the path if average height of the trees on the street is maximal of all average heights of the trees on the streets along the path. We will introduce a term "the highest average" of the path as the highest value of all the average heights of the trees on all the streets along the path.
In order to satisfy both of them, they have decided to choose a path that is the shortest of all possible paths from town Izelgard to Deronjilous city (if any path exists at all) and if there are more such paths, then they choose a path that has maximal "highest average" of all the shortest paths.
9 12
1 2 1 5
1 3 2 8
1 4 3 2
2 6 5 3
3 5 2 12
4 5 1 22
4 9 9 9
5 7 3 1
6 7 1 10
6 8 1 2
7 9 5 8
8 9 100 100Output:
12 22Explanation:
There are 4 shortest paths, each of length 12. All shortest paths (represented by their endpoints) are:
1-2-6-7-9
1-3-5-7-9
1-4-5-7-9
1-4-9
We choose the 3rd path because its highest average is 22, that is greater than highest average of all the other shortest paths.
5 8
5 4 1 1
5 3 1 1
5 2 1 1
4 3 1 1
4 1 1 1
3 2 1 1
3 1 1 1
2 1 1 1Output:
2 1Explanation:
All paths have highest height 1.
4 3
1 2 10 10
1 3 10 10
2 3 15 5551Output:
-1 -1Explanation:
There is no any street associated with Deronjilous city.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.