eolymp
bolt
Try our new interface for solving problems
Problems

Happy Birthday

Happy Birthday

Then came the long-awaited birthday. Only one test left - find a way to Ira's home. The most popular form of transport in the city are buses. Each bus has two drivers, one of them knows one route, and the other - other route. However the time and place of start are the same for both bus drivers. Each day one of the drivers is working, and the other is resting. If Alex is on a bus stop, he will immediately know which drivers are now working on buses departing from this stop. However, before he reaches the stop, he only knows the schedule of possible movement of buses and the probabllity that the rst driver works today. Sasha lives near a bus stop with number \textbf{1} and can be on it at any time, and Ira lives near to the stop \textbf{N}. Find the average arrival time for Sasha. At the same time Sasha would never use a way that could cause not reaching Ira's home at all, but among all the other he chooses the one that minimizes the expected time of arrival. Important facts: \begin{itemize} \item Network trafic of buses is an acyclic directed graph. \item You can instantly change from one bus to another one. \item In determining the optimal strategy Sasha also counts that on arrival at each stop, he gets the informations about today's drivers. \item Initially, Sasha doesn't know extra information even about his stop. \end{itemize} \InputFile In the first row are given two integers \textbf{N} and \textbf{K} (\textbf{2} ≤ \textbf{N} ≤ \textbf{10^5}, \textbf{0} ≤ \textbf{K} ≤ \textbf{10^5}) --- the number of stops and buses. In each of the next \textbf{K} lines information about buses is described: seven integers \textbf{u d p v_1 a_1 v_2 a_2} (\textbf{1} ≤ \textbf{u}, \textbf{v_1}, \textbf{v_2} ≤ \textbf{N}, \textbf{u} ≠ \textbf{v_1}, \textbf{u} ≠ \textbf{v_2}, \textbf{0} ≤ \textbf{d}, \textbf{a_1}, \textbf{a_2} ≤ \textbf{1440}, \textbf{d} < \textbf{a_1}, \textbf{d} < \textbf{a_2}, \textbf{0} < \textbf{p} < \textbf{100}) --- number of stops and time of departure, the probability that the rst driver works, place and time of arrival, for first and for second driver, respectively. \OutputFile Print average arrival time to \textbf{N}'th stop for Sasha with an absolute or a relative error of \textbf{10^\{-6\}}, or \textbf{-1}, if there is a nonzero probability of not getting there at all.
Time limit 1 second
Memory limit 256 MiB
Input example #1
5 6
1 60 50 2 200 3 150
1 100 25 2 160 3 150
1 200 50 5 350 4 300
2 180 50 5 300 4 280
3 400 80 5 600 5 660
4 350 50 5 500 5 550
Output example #1
423.4375000000000