This page is still under construction.

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

Pleasant Path

Time limit3sMemory limit1024 MB

Summary
In a DAG with places ordered toward home, find the path from 1 to n maximizing the average edge weight.
Level

Medium7 of 10

Topics
Binary search, Dynamic programming, Graph, Greedy
Solved
No attempts yet

Problem

When I walk home, I do not always take the shortest route. I take a route that a) keeps bringing me closer to home and b) is the "pleasantest", meaning the average pleasantness factor of the road segments I pass is as high as possible. Write a program that computes the maximum such average.

The map of my city can be described with nn places numbered from 11 to nn. Place 11 is my starting point and place nn is my home, and the places are sorted by distance so that a place with a higher number is always closer to home than one with a lower number.

There are also mm different "road segments", each going from one place u_iu\_i to another place v_iv\_i and having a pleasantness factor w_iw\_i, which might come from unusual trees, a cute cat in a window, or something else pleasant. Since I always want to walk in the direction of home, the description includes only road segments with u_i<v_iu\_i<v\_i.

Someone with a bit of mathematical interest (if there is such a person in this company) might call this a directed, weighted acyclic graph.

The map in the second sample. The pleasantest path is 1→3→51\rightarrow 3\rightarrow 5.

Input

The first line contains the two integers nn and mm (2≤n≤1052 \leq n \leq 10^5 , 1≤m≤2⋅1051 \leq m \leq 2\cdot 10^5). Each of the following mm lines describes one road segment and contains three integers u_iu\_i, v_iv\_i, w_iw\_i (1≤u_i<v_i≤n1 \leq u\_i < v\_i \leq n, 1≤w_i≤2⋅1061 \le w\_i \le 2\cdot 10^6), meaning the road segment goes from place u_iu\_i to place v_iv\_i and has pleasantness factor w_iw\_i.

No two road segments connect the same pair of places, and it is guaranteed that place nn is reachable from place 11.

Output

Print one number: the highest achievable average of the pleasantness factors along a path from place 1 to place nn. The answer is considered correct if it has a relative or absolute error of at most 10−610^{-6}.

Examples2

  1. Example 1

    Input
    3 3
    1 2 20
    2 3 17
    1 3 18
    
    Expected output
    18.5000000000
    
  2. Example 2

    Input
    5 6
    1 2 20
    2 3 17
    1 3 18
    4 5 19
    3 5 23
    2 4 22
    
    Expected output
    20.5