| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 
 | #include <bits/stdc++.h>#define MAX_N 100000
 #define MAX_M 100000
 #define EPS 1e-5
 #define INF 0x3f3f3f3f
 #define mid ((l+r)/2)
 using namespace std;
 typedef double dnt;
 template <class T>
 inline void read(T &x) {
 x = 0; int c = getchar(), f = 1;
 for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
 for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
 }
 struct node {int v, c, nxt; dnt w;} E[MAX_M+5];
 struct edge {int u, v, a, b, c, d;} e[MAX_M+5];
 int n, m, s, t, cnt, pr[MAX_N+5], cr[MAX_N+5];    dnt mic, tot;
 void init() {s = n+1, t = n+2, cnt = 0, mic = tot = 0.0, memset(pr, -1, sizeof pr);}
 void insert(int u, int v, int c, dnt w) {E[cnt] = (node){v, c, pr[u], w}, pr[u] = cnt++;}
 void addedge(int u, int v, int c, dnt w) {insert(u, v, c, w), insert(v, u, 0, -w);}
 bool SPFA() {
 queue <int> que;	bool inq[MAX_N+5];	memset(inq, false, sizeof inq);
 dnt d[MAX_N+5];	int cr[MAX_N+5];	for (int i = 1; i <= t; i++) d[i] = INF;
 d[s] = 0, que.push(s), inq[s] = true, memset(cr, -1, sizeof cr);
 while (!que.empty()) {
 int u = que.front();	que.pop(), inq[u] = false;
 for (int i = pr[u]; ~i; i = E[i].nxt) {
 int v = E[i].v, c = E[i].c;	dnt w = E[i].w;
 if (c && d[u]+w < d[v]) {
 d[v] = d[u]+w, cr[v] = i;
 if (!inq[v]) que.push(v), inq[v] = true;
 }
 }
 }
 if (fabs(d[t]-INF) <= EPS) return false;	int flow = INF;
 for (int i = cr[t]; ~i; i = cr[E[i^1].v]) flow = min(flow, E[i].c);
 for (int i = cr[t]; ~i; i = cr[E[i^1].v]) E[i].c -= flow, E[i^1].c += flow;
 mic += 1.0*flow*d[t];	return true;
 }
 bool chk(dnt tans) {
 init();
 for (int i = 1; i <= m; i++)
 addedge(e[i].u, e[i].v, e[i].c, e[i].d-e[i].a-tans);
 for (int i = 1; i <= m; i++) if (e[i].u^s)
 addedge(e[i].u, e[i].v, INF, e[i].b+e[i].d+tans);
 for (int i = 1; i <= m; i++)
 tot += (e[i].a-e[i].d+tans)*e[i].c;
 while (SPFA()) ;	return tot+mic <= -EPS;
 }
 dnt bi_search(dnt l, dnt r) {
 dnt ret = -1.0;
 while (r-l >= EPS)
 if (!chk(mid)) r = mid;
 else ret = mid, l = mid;
 return ret;
 }
 int main() {
 read(n), read(m);
 for (int i = 1; i <= m; i++)
 read(e[i].u), read(e[i].v), read(e[i].a),
 read(e[i].b), read(e[i].c), read(e[i].d);
 return printf("%.2lf", bi_search(0.0, 30000.0)), 0;
 }
 
 |