This problem is to give you a map, each side has a maximum load, now have x cow from vertex 1 to vertex n, each cow to load the same weight, ask you to load how much weight? Can be two-point answer, calculate the weight of each cow, and then modify the edge, run the maximum flow can be judged whether the current answer is correct, two-point answer can be, note because the original Benquan/cattle load capacity may be very large, so we should be aware of this point when modifying the edge, the maximum value of edge control within 1000000, To prevent overflow, the code is as follows:
#include <bits/stdc++.h>using namespacestd;Const intMAXN = -;intN, m, X;structdinic{intN; structEdge {int from, to, Cap;}; Vector<int>G[MAXN]; Vector<edge>e; intLEVEL[MAXN], ITER[MAXN]; voidinit () { for(intI=0; i<=n; i++) g[i].clear (); E.clear (); } voidAdd_edge (intUintVintcap) {E.push_back (Edge) {u, V, cap}); E.push_back (Edge) {V, u,0}); intm =e.size (); G[u].push_back (M-2); G[v].push_back (M-1); } voidBFsints) {memset (level,-1,sizeof(level)); Queue<int>que; Level[s]=0; Que.push (s); while(!Que.empty ()) { intU =Que.front (); Que.pop (); for(intI=0; I<g[u].size (); i++) {Edge&te =E[g[u][i]]; if(te.cap>0&& level[te.to]<0) {level[te.to]= Level[u] +1; Que.push (te.to); } } } } intDfsintVintTintf) { if(v = = t)returnF; for(int&i=iter[v]; I<g[v].size (); i++) {Edge&TPE =E[g[v][i]]; if(tpe.cap>0&& level[v]<Level[tpe.to]) { intD =dfs (tpe.to, T, Min (f, tpe.cap)); if(D >0) {Tpe.cap-=D; E[g[v][i]^1].cap + =D; returnD; } } } return 0; } intMax_flow (intSintt) { intFlow =0; for( ;; ) {BFS (s); if(level[t]<0)returnflow; memset (ITER,0,sizeof(ITER)); intF; while(F=dfs (S, T,0x3f3f3f3f)) >0) Flow + =F; }}}di, Di2;BOOLCheckDoublemid) {DoubleEve = Mid/(Double) x; Di2=di; for(intI=0; I<di2.e.size (); i++) {Di2.e[i].cap= Min ((Double) Di2.e[i].cap/eve, (Double)1000000+ -); }//printf ("-----------\ n");//for (int i=0; i<di2.e.size (); i++) {//if (di2.e[i].cap) printf ("%d%d%d\n", Di2.e[i].from, Di2.e[i].to, di2.e[i].cap);// } intres = Di2.max_flow (1, N); returnRes >=x;}intMain () {scanf ("%d%d%d", &n, &m, &x); DI.N=N; Di.init (); for(intI=0; i<m; i++){ intu, V, c; scanf ("%d%d%d", &u, &v, &c); Di.add_edge (U, V, c); } DoubleL=0, R= (Double)0x3f3f3f3f; Doubleres =0; for(intI=0; i< +; i++) { DoubleMid = (l+r)/2; if(check (mid)) {res=mid; L=mid; } ElseR =mid; } printf ("%.10f\n", RES); return 0;}
Indiahacks 2016-online Edition (div. 1 + div. 2) Two-point answer + network flow