CHICAGO - 106 miles to Chicago

In the movie "Blues Brothers", the orphanage where Elwood and Jake were raised may be sold to the Board of Education if they do not pay 5000 dollars in taxes at the Cook County Assessor's Office in Chicago. After playing a gig in the Palace Hotel ballroom to earn these 5000 dollars, they have to find a way to Chicago. However, this is not so easy as it sounds, since they are chased by the Police, a country band and a group of Nazis. Moreover, it is 106 miles to Chicago, it is dark and they are wearing sunglasses.

As they are on a mission from God, you should help them find the safest way to Chicago. In this problem, the safest way is considered to be the route which maximises the probability that they are not caught.

Input Specification

The input file contains several test cases. Each test case starts with two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ n*(n-1)/2). n is the number of intersections, m is the number of streets to be considered.

The next m lines contain the description of the streets. Each street is described by a line containing 3 integers a, b and p (1 ≤ a, b ≤ n , a ≠ b, 1 ≤ p ≤ 100): a and b are the two end points of the street and p is the probability in percent that the Blues Brothers will manage to use this street without being caught. Each street can be used in both directions. You may assume that there is at most one street between two end points.

The last test case is followed by a zero.

Output Specification

For each test case, calculate the probability of the safest path from intersection 1 (the Palace Hotel) to intersection n (the Honorable Richard J. Daley Plaza in Chicago). You can assume that there is at least one path between intersection 1 and n.

Print the probability as a percentage with exactly 6 digits after the decimal point. The percentage value is considered correct if it differs by at most 10-6 from the judge output. Adhere to the format shown below and print one line for each test case.

Sample 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

Sample Output

61.200000 percent

The safest path for the sample input is 1 → 4 → 3 → 5


Added by:Adrian Kuegel
Date:2005-06-24
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: PERL6
Resource:University of Ulm Local Contest 2005

hide comments
2024-11-21 09:09:53
Why it print 61,2%?
2023-09-01 13:32:07
<snip>
Please tell anyone what I am doing wrong in this floyd warshal implementation
[Simes]: this is not the place for a code review, use the forum.

Last edit: 2023-09-01 16:29:19
2023-09-01 13:30:25
from where can we get solutions, I don't know what I am doing wrong and we can't even see test cases, So bad for beginners
2020-08-18 13:51:36
Can this really be solved using Dijkstra?
getting TLE!!
2020-08-12 19:16:02
Don't get deceived by the comments,dijikstra is enough.


Last edit: 2020-08-13 05:25:32
2020-07-16 15:02:22
n is number of streets and m is number of intersections.
Can be solved using Dijkstra or Floyd Warshall.
2020-04-02 23:50:00
Use max heap priority queue in Dijsktra.
2019-10-26 19:07:45
Dijkstra with bit modification .
2019-08-19 06:41:08
don't forget to print " percent" after answer
gave me one WA :-(
2019-07-19 12:08:49
wasted so many attempts by using greedy algorithms.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.