import scala.collection.mutable
import scala.io.StdIn._

object Main extends App {
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val edges = Array.tabulate(m){_ ⇒
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    Edge(a, b, c, d)
  }
  if (m == n - 1) {
    println(0.0)
  }else {
    var min = 0.0
    var max = Double.MaxValue / 2
    while (min + 0.000000001 < max) {
      val mid = (min + max) / 2
      if (canMake(edges, mid)) max = mid
      else min = mid
    }
    println("%.10f".format(min))
  }
  def canMake(edges: Array[Edge], target: Double): Boolean = {
    if (edges.length == n - 1) true
    else {
      val union = new UnionFind(n)
      var unuseLength = 0.0
      var unuseJob = 0.0
      for (Edge(a, b, c, d) ← edges.sortBy(e ⇒ e.d - e.c * target)(Ordering.Double.reverse)) {
        if (union.isSame(a, b)) {
          unuseLength += c
          unuseJob += d
        }else {
          union.merge(a, b)
        }
      }
      (unuseJob / unuseLength) <= target
    }
  }
}
case class Edge(a: Int, b: Int, c: Int, d: Int)
class UnionFind(val size: Int) {
  private val parent = Array.fill(size){-1}
  def find(a: Int): Int = {
    if (parent(a) >= 0) {
      parent(a) = find(parent(a))
      parent(a)
    }else a
  }
  def isSame(a: Int, b: Int): Boolean = find(a) == find(b)
  def merge(a: Int, b: Int): Unit = {
    val ar = find(a)
    val br = find(b)
    if (ar != br) {
      if (parent(ar) < parent(br)) {
        parent(ar) += parent(br)
        parent(br) = ar
      }else {
        parent(br) += parent(ar)
        parent(ar) = br
      }
    }
  }
}
