#include<bits/stdc++.h>

using namespace std;

int N, M;

struct edge
{
  int u, v, cost, time;
  double p;

  edge(int u, int v, int cost, int time) : u(u), v(v), cost(cost), time(time) {};

  bool operator<(const edge &e) const
  {
    return p < e.p;
  }

};

typedef vector< edge > Edges;

class DisjointSet
{
private:
  vector< int > rank, p;

  void link(int x, int y)
  {
    if(rank[x] > rank[y]) {
      p[y] = x;
    } else {
      p[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }

public:
  DisjointSet() {}

  DisjointSet(int size)
  {
    rank.resize(size, 0);
    p.resize(size, 0);
  }

  void makeSet(int x)
  {
    p[x] = x, rank[x] = 0;
  }

  void Union(int x, int y)
  {
    link(findSet(x), findSet(y));
  }

  int findSet(int x)
  {
    return (x != p[x] ? p[x] = findSet(p[x]) : p[x]);
  }
};

double kruskal(Edges &edges, int V)
{
  sort(edges.rbegin(), edges.rend());
  DisjointSet uf_tree(V);
  for(int i = 0; i < V; i++) {
    uf_tree.makeSet(i);
  }
  double ret = 0;
  for(int i = 0; i < edges.size(); i++) {
    edge &e = edges[i];
    ret += e.p;
  }
  for(int i = 0; i < edges.size(); i++) {
    edge &e = edges[i];
    if(uf_tree.findSet(e.u) != uf_tree.findSet(e.v)) {
      uf_tree.Union(e.u, e.v);
      ret -= e.p;
    }
  }
  return ret;
}

bool calc(Edges &edges, double value)
{
  double ret = 0.0;
  for(int i = 0; i < edges.size(); i++) {
    edge &e = edges[i];
    e.p = (double) e.cost - (double) e.time * value;
  }
  return kruskal(edges, N) <= 0.0;
}

int main()
{
  Edges edges;
  scanf("%d %d", &N, &M);
  for(int i = 0; i < M; i++) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    edges.push_back(edge(a, b, d, c));
  }
  double row = 0.0, high = 1e9;
  for(int i = 0; i < 100; i++) {
    double mid = (row + high) / 2;
    if(calc(edges, mid)) high = mid;
    else row = mid;
  }
  cout << fixed << setprecision(5) << (high + row) / 2 << endl;
}