106 Miles to Chicago
InterviewTime limit1sMemory limit128 MB
Given a graph where each edge has a percent probability of staying uncaught, find the path from node 1 to node n that maximizes the product of these probabilities.
- Level
Medium5 of 10
- Topics
- Graph, Shortest path, Greedy, Math
- Solved
- No attempts yet
Problem
In the movie The Blues Brothers, the orphanage where Elwood and Jake grew up will be sold to the Board of Education unless they pay $5000 in back taxes to the Cook County Assessor's Office in Chicago. After earning that money by playing a gig in the Palace Hotel ballroom, they have to find a way to Chicago.
This is not as easy as it sounds: they are chased by the police, a country band, and a group of Nazis. On top of that, it is 106 miles to Chicago, it is dark, and they are wearing sunglasses.
Since they are on a mission from God, help them find the safest route to Chicago. Here, the safest route is the one that maximizes the probability of not being caught.
Input
The input contains several test cases.
Each test case begins with two integers and (, ), where is the number of intersections and is the number of streets.
Each of the next lines describes one street with three integers , , and (, , ): and are the two endpoints of the street, and is the probability, in percent, that the Blues Brothers can use this street without being caught. Every street can be traveled in both directions, and there is at most one street between any pair of intersections.
The input ends with a line containing a single zero, which is not part of any test case.
Output
For each test case, compute the probability of the safest path from intersection (the Palace Hotel) to intersection (the Honorable Richard J. Daley Plaza in Chicago). There is always at least one path between intersection and intersection .
Print this probability as a percentage with exactly six digits after the decimal point, followed by a single space and the word percent. Print one line for each test case.