Drunken Walk

No attempts yetTime limit2sMemory limit512 MB

Problem

After a few too many drinks in the evening, you set off on a long walk over a directed graph — but not endlessly long, because the graph has no cycles.

You start at vertex 00. Whenever you are at a vertex, you leave it along one of its outgoing edges, choosing each outgoing edge at random with probability proportional to that edge's weight. You keep walking until you reach a vertex with no outgoing edges, at which point you fall asleep and the walk ends. The length of your walk is the number of edges you traverse.

Before you start (that is, before leaving vertex 00), you may pick one edge anywhere in the graph that you dislike and ignore it for the entire walk, or you may choose to ignore no edge at all. Ignoring an edge removes it from the graph, so a vertex whose only outgoing edge you ignore becomes a place where you fall asleep.

Determine the largest possible expected length of your walk.

Input

The input contains several test cases. Each test case starts with a line containing two integers NN and MM (2N10,0002 \le N \le 10{,}000, 1M100,0001 \le M \le 100{,}000): the number of vertices and the number of edges of the graph. Each of the next MM lines contains three integers uu, vv, and ww (1w1,0001 \le w \le 1{,}000), meaning there is a directed edge from vertex uu to vertex vv with weight ww (vertices are numbered from 00 to N1N-1). The graph is guaranteed to contain no directed cycles. The input ends with a line containing N=M=0N = M = 0, which must not be processed.

Output

For each test case, print on its own line the largest possible expected length of your walk, rounded to exactly 88 digits after the decimal point.