This page is still under construction.

Parts of this page are still being built. What you see may change.

106 Miles to Chicago

Interview

Time limit1sMemory limit128 MB

Summary
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 nn and mm (2≤n≤1002 \le n \le 100, 1≤m≤n(n−1)/21 \le m \le n(n-1)/2), where nn is the number of intersections and mm is the number of streets.

Each of the next mm lines describes one street with three integers aa, bb, and pp (1≤a,b≤n1 \le a, b \le n, a≠ba \ne b, 1≤p≤1001 \le p \le 100): aa and bb are the two endpoints of the street, and pp 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 11 (the Palace Hotel) to intersection nn (the Honorable Richard J. Daley Plaza in Chicago). There is always at least one path between intersection 11 and intersection nn.

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.

Examples3

  1. Example 1

    Input
    5 7
    5 2 100
    3 5 80
    2 3 70
    2 1 50
    3 4 90
    4 1 85
    3 1 70
    0
    
    Expected output
    61.200000 percent
    
  2. Example 2

    Input
    2 1
    1 2 50
    0
    
    Expected output
    50.000000 percent
    
  3. Example 3

    Input
    2 1
    1 2 100
    0
    
    Expected output
    100.000000 percent